I've inherited some nice looking code that uses Application.ActivityLifecycleCallbacks. We're using the onActivityResumed
method to take users back to a login screen when their session has timed out.
There's no documentation in the API docs about how this works. Do we get any guarantees about when these methods are called (i.e. are they called before the corresponding onResume
in the Activity), and whether they are synchronous with the normal life cycle methods?
If I had to guess, I'd assume these happen in parallel, which means individual activities/fragments would still need to safely cope with being logged out.
These are called on the main (UI) thread and they are called serially (not in parallel). These callbacks are made in the
Activity
class, so they are made when your activity callssuper.onXXXXX()
;As an example, see
getApplication().dispatchActivityResumed(this);
in Activity.onResume() in the Android source code.