kaeppler/droid-fu — Issue #65: isApplicationBroughtToBackground doesn't *always* report the right value
Author: schnalle
Created: 2011-10-25 15:42:59+00:00
State: open

i use the `isApplicationBroughtToBackground` method (standalone, not the the whole doid-fu package) to implement a security feature that displays a locking screen if my app regains the focus after coming back from a different app.

now, the problem was that the security gesture *sometimes* showed twice. after digging around a bit i noticed that if the `isApplicationBroughtToBackground` method is called again directly **after** returning from the background (in my case because the launch of the security activity after coming back triggered the onPause method of the launching activity), **the topActivity from ActivityManager.getRunningTasks(1) is sometimes still the activity you just returned from**.

i suspect that maybe activities that do a lot of cleanup after being closed may linger on top of the RunningTasks stack for a short time, but if onPause is called again right after returning the short time might be enough to register as a second isApplicationBroughtToBackground, when this is not actually the case.

in my case, the offending lingering app was `com.android.mms`, but other apps triggered it too.