When to call super.onPause ()?

I use Analytics in my Android app and I would like to know when to call super.onPause()

 if (mAnalyticsSession != null) { mAnalyticsSession.close(); mAnalyticsSession.upload(); } super.onPause(); 

What is the effect of calling super.onPause() after performing the load actions before and after?

In general, when do you need to call super.onPause() ?

+7
source share
2 answers

You call super.onPause() only in your own override of Activity.onPause() .

 public class YourActivity extends Activity { @Override public void onPause() { super.onPause(); // Do your stuff, eg save your application state } } 

Note that you do not need to override this if you do not need it. If you are going to override it, then do not slow processes here, or you can get ANR.

+4
source

The selected answer is incorrect (I know this is an old question, but for new readers the right way is here: Add your codes after Super.onPause or Super.OnStart, ... And here is the Android link for your question (direct link in the comment):

Quote from: Your implementation of these lifecycle methods should always invoke the implementation of the superclass before doing any work.

+14
source

All Articles