Search code examples
androidandroid-lifecycle

When to call super.onPause()?


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()?


Solution

  • 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.