Lifecycle of fragments when user "quits"

1.7k views Asked by At

I have a main activity which is showing/hiding a bunch of fragments. There is a login activity at the very start that logs the user in. When the user presses home or the multi-tasking button, the app should start a timer that (after the timer runs out) automatically logs the user out. This could be when the user returns to the app (and timer has run out -> logout) or while in the app and has done nothing.

What exactly gets called when the user presses home/multi-tasking button in terms of the fragment's lifestyle methods? In my quick tests, it seems that the first fragment in the fragment manager's onPause is called everytime no matter the fragment on screen when the user exits out.

How can i go about this?

2

There are 2 answers

6
Philipp Jahoda On BEST ANSWER

Please have a look at this tutorial about the Fragment-Lifecycle:

http://developer.android.com/reference/android/app/Fragment.html#Lifecycle

It explains the lifecycle of the Fragment with respect to its Activity.

When the user presses the home-button for example:

onPause() - fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity.

0
Oscar Rene On

The methods called on the fragment's lifecycle are the same that the activity's. You can check the complete set of methods that are called right here: Fragments