简体   繁体   中英

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

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

Quote from Activities: Your implementation of these life-cycle methods must always call the superclass implementation before doing any work.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM