/ android

Android activity running state

We had been encountering a rather odd bug with our Network state change handlers on the Tenreads app. This, an issue that would show up only on certain devices/API versions. In this case, it was a Redmi and a Motorola device both of which were running Kitkat.

The network state change handler extended from the native BroadcastReceiver. Its onReceive method, as norm, had functional flows to redirect to the previous view. The key here was to not transition when the app went to the background.

To ensure this, we depended on using the ActivityManager.RunningAppProcessInfo class. This class provides information about all the running processes. Upon filtering based on processName from getRunningAppProcesses, we check for the importance state.

The issue with the two reported devices/API levels stemmed from here, on observation. Both of these devices/APIs, returned a level of IMPORTANCE_FOREGROUND. This, when the app went away to the background on user action. Queer, and without any sensible reasoning.

The fix was to check for the importance state to be IMPORTANCE_VISIBLE. This state, from docs, indicates the app running something visible to the user.

One of those times, when the fine print in the docs aren't quite enough dealing with the real world.