I am implementing Analytics in my android application, and I would like advice on when to call super.onPause()
if (mAnalyticsSession != null) {
mAnalyticsSession.close();
mAnalyticsSession.upload();
}
super.onPause();
What is the effect of calling super.onPause()
after doing upload actions vs. before?
In general, when should one call super.onPause()
?
onResume() will always be called when the activity goes into foreground, but it will never be executed before onCreate() .
An activity can frequently transition in and out of the foreground—for example, onPause() is called when the device goes to sleep or when a dialog appears. Because this state can transition often, the code in these two methods should be fairly lightweight in order to avoid slow transitions that make the user wait.
onPause. Called when the Activity is still partially visible, but the user is probably navigating away from your Activity entirely (in which case onStop will be called next). For example, when the user taps the Home button, the system calls onPause and onStop in quick succession on your Activity .
onResume() is one of the methods called throughout the activity lifecycle. onResume() is the counterpart to onPause() which is called anytime an activity is hidden from view, e.g. if you start a new activity that hides it. onResume() is called when the activity that was hidden comes back to view on the screen.
You only call super.onPause()
in your own Activity.onPause()
override.
public class YourActivity extends Activity {
@Override
public void onPause() {
super.onPause();
// Do your stuff, e.g. save your application state
}
}
Note that you don't need to override this if you don't need it. If you're going to override it, then do not make slow processes in here or you might get an ANR.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With