Photo by Mika Baumeister on Unsplash

Google provides a feature in the Play Core library to prompt apps users to install a more recent version directly within your app.

Be it flexible (not mandatory) or immediate (mandatory), this feature enable the developper to encourage users to stay up to date with the versions or can even compell the user to update before using the app in case of breaking changes.

A few requirements to use this feature:

First things first, there is a bit of code to write…


Seeing this kind of code is quite common nowadays. A fragment observe a livedata coming from a viewmodel and make something with it.

calendarViewModel.calendarRows.observe(viewLifecycleOwner) { rows -> rows.size }

However, if you instantiate a second time the fragment containing this code, you might encounter this lovely exception:

java.lang.IllegalArgumentException: Cannot add the same observer with different lifecycles

What happens is that the lambda becomes a singleton and is reused every time a new fragment is attached with each fragment not sharing the same lifecyle state.

If you reuse the same fragment via findFragmentByTag for example, you shouldn’t face the exception.

Let’s…


Comment Android gère le système backpress ?

Que se passe-t-il quand l’utilisateur clique sur le bouton ‘retour système’ sur son téléphone ?
Si notre activity hérite de AppCompatActivity, voici la hiérarchie d’héritage de votre activity jusqu’à Activity qui est la 1ère classe à gérer le backpress :

AppCompatActivity -> FragmentActivity -> androidx.activity.ComponentActivity -> androidx.core.app.ComponentActivity -> Activity

Le comportement par défaut de Activity

Android gère ce comportement grâce à un callback quand l’utilisateur relâche une touche et que le code de cette touche est le bouton back du téléphone.

Pour les versions supérieures à Android Eclair, le callback est mappé sur OnkeyUp qui va faire appel à une méthode onBackPressed définie dans la classe…


Detekt est un analyseur statique de code capable de vous pointer de très nombreux points d’amélioration sur votre code Kotlin.

Detekt : un analyseur statique de code pour améliorer la qualité de votre code Kotlin
Kotlin — Photo by Marc Reichelt

Que ce soit sur un projet back-end ou Android, en local ou sur votre CI, Detekt vous remontera les écarts aux bonnes pratiques de développement communément acceptées.

Pour l’exemple, nous allons l’intégrer sur un projet Android et l’inclure dans une CI à l’aide de Github actions. C’est bien sûr à adapter en fonction du projet.

L’installation via Gradle

Dans le fichier build.gradle du projet, il nous faut rajouter la dépendance et le plug-in.

build.gradle

Dans le fichier build.gradle de votre module, il faudra apply le plug-in pour lui permettre d’ajouter les nouvelles Tasks au build.

build.gradle

Il existe de nombreuses options de configuration…


Android Espresso instrumented test

Most of the time, android apps work with a rest api.

Libs like Retrofit, Koin make it easy to interact with this rest api. However, it’s not so easy when running instrumented tests.

First, we should disable the animations. Otherwise the tests are gonna crash. I haven’t found a better than this one for now.

adb shell settings put global window_animation_scale 0.0
adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0

The purpose of the lib MockWebServer is obvioulsy to mock a web server. We can send our requests to mockwebserver instead of the remote…


It’s a common use case in an android app to warn your app user he’s not connected anymore or refresh data when the network is back.

With LiveData, it’s become very easy to do so. Thanks to the broadcast receiver for connectivity change, we are pinged during a change and can determine exactly all the info needed from the network with the ConnectivityManager.

According to the google doc, it’s more resource friendly to register a broadcast receiver when needed. That’s why with a live data object, if no one is observing it, the broadcast receiver is not registered. On the contrary, as soon as the live data object is not active anymore, we unregister the broadcast receiver. We can apply this network status listener only in views where it matters for the app users.


Let’s say you have a list of json objects that you want to import in MongoDB in order to make GeoSpatial queries on the fields longitude and latitude.

With the following format, Mongo cannot perform these queries. It needs to have a valide GeoJSON field. Multiple methods exists : legacy coordinates or a Point.

We can observe as well that the fields as in the json object is a string. When we import the data with the mongoimport tool, it won’t convert these values as floats.

import.json

First let’s import the data in a collection dvf for this example.

mongoimport…


ARCore

While trying to learn more about ARCore, I faced the yearning to build an AR Portal.

Most of the examples I found on the web were made with Unity. I tried and it works great indeed. ARCore with Unity is very powerful.

But what if an AR experience is simply a bonus to your app and not the main feature. I want to build a native Android App with a bit of AR flare not a full powered AR app.

Thus, I decided to take on the challenge of building an AR Portal with only plain ARCore and Sceneform. …


Use a self-signed, a non public certificate authority or even an HTTP endpoint in android studio, with a targetSdkVersion 28

As of Android Pie, network requests must be pass through HTTPS unless specified otherwise.

However during the developpment phase for instance, you could face use cases where you don’t have access to a ssl certificate trusted by android(ex: let’s encrypt).

First Use case: a hobby project with a http endpoint

Let’s say you mock your endpoint but still want to test a real network connection.

I usually use mocky.io to mock api responses. At a given url, your predefined response is sent back.

For a given mocked url “http://www.mocky.io/v2/xxxxxxxxxxxxx”, as…


Set up two backends over HTTPS with a reverse proxy

As you may know, serving a website over HTTP is a big no no. Google marks a website as insecure if the traffic is not encrypted.

When at least a few pages of a website are shared among a large number of visitors, you may choose to use a reverse proxy (let’s say Varnish 4) to relieve the traffic on your backend.

Since Varnish does not support SSL out of the box, we are facing a genuine conundrum.

There is a solution of course, not ideal but very effective nonetheless.

Julien Bouffard

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store