When you press the Home button, Acivity is destroyed.

In my application, when I click the home button, the activity will be onDestroy() . Suppose the onPause() method is only called correct?

Why is this happening?

+8
android android-activity ondestroy
source share
4 answers

Depending on the memory capacity of your phone, if your phone does not have a lot of memory, it will destroy the action to free up resources immediately. This will not happen on new phones because they have a lot of spare memory.

+11
source share

Activity can be destroyed when you press the home button if the system is limited and determines that it needs to free some resources. The documentation states that onDestroy() can be called if:

This can happen either because the operation is completed (someone calls its final (), or because the system temporarily destroys this instance of the action in order to save space. You can distinguish between these two scenarios with the isFinishing () method.

Also, note that the system can kill your program without calling onDestroy() after calling onStop() . Therefore, any code to save / save data should be in onPause() or onStop() .

+5
source share

also check that you are not using the android: noHistory flag in your manifest for Activity

Documentation: android: noHistory Regardless of whether to remove an action from the action stack and complete it (its finish () method) when the user moves from it and it is no longer displayed on the screen

+5
source share

Well, it depends on many factors. If you encounter this problem on Android 3.2+ devices, you should add the screenSize property in android: configChanges

  android:configChanges="keyboardHidden|orientation|screenSize" 

Also, add android: launchMode = "singleTop" to your launch activity. Please note that you need to use the Android SDK 15 or higher as the target, however your application will also work on older devices. Hope this helps.

0
source share

All Articles