A more complete Activity Lifecycle

Written by Xavier Gouchet - 05 february 2013 - no comments

In one of my application, I want to perform an action when the user has been idle for more than n minutes.

While searching the web I found those two callbacks in the Activity class : onUserInteraction() and onUserLeaveHint , both available since Cupcake.

The first one is simply called whenever an interaction is consumed by the activity : touch, key event, trackball event. The second is called just before onPause() when the user leaves your Activity on purpose. For example by pressing the home button, launching another activity from the notification bar. It won't be called when an Activity generated by the system comes in the foreground (an incoming phone call for instance).

And there are a lot more callbacks in an Activity that one can override. So, after some extensive logging and reading through AOSP sources, here's a new and more complete Activity lifecycle graph, with all the callbacks one may find usefull. I also included the callbacks sent to an Activity's fragments.

Android Full LifeCycle

Feel free to add any remark to make this diagram as accurate as possible.

Write a comment

Enter image code :