Activity is getting destroyed while pressing the home button

前端 未结 6 803
感动是毒
感动是毒 2020-12-19 03:50

In my application, when I press the home button the activity is going to onDestroy(). It suppose to be called onPause() method only right?

6条回答
  •  甜味超标
    2020-12-19 03:53

    You activity could be destroyed upon pressing the home button if the system is constrained and has determined it needs to free some resources. The documentation states that onDestroy() can be called if:

    This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

    Additionally, do note that the system can kill your program without calling onDestroy() after onStop() has been called. Therefore, any cleanup/data persistence code should be in either onPause() or onStop().

提交回复
热议问题