I am using this 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 is that the security feature is sometimes shown twice. After digging around a bit I noticed that the topActivity from ActivityManager.getRunningTasks(1) is sometimes still the activity you just returned from.
In my case, the offending lingering apps are com.android.mms and com.google.android.apps.maps.
I have a calling facility as well within the application but it is not misbehaving.
I am completely baffled with this behavior.