Android Application class lifecyle documentation

前端 未结 2 547
感情败类
感情败类 2021-02-09 15:49

I\'m trying to find the official documentation about the Android Application class lifecycle. Apparently, for what I found on StackOverflow here and he

2条回答
  •  梦毁少年i
    2021-02-09 16:33

    As far as I know, you can't handle the application killed event. Here is a quote from the Application's onTerminate method:

    This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.

    The general idea is that you shouldn't care whether the application was killed or not. If it was, the OS will restart the app next time it is needed otherwise it will be resume (and you'll use the Activity / Fragment lifecycle events to achieve this).

    What data do you need to store - is it possible to store it earlier (when it is received from web service and so on) instead of waiting for the last moment?

提交回复
热议问题