简体   繁体   中英

Android tablet and phone activity behaviours when home button is pressed

I have my tournament maker app installed on my phone version 2.2 and a tablet version 4.0.3.

When I launch the app from my phone and begin an activity, it doesn't get destroyed and recreated when I press the home button and then launch it again (which is what I want).

When I do the same thing from my tablet, the activity seems to get destroyed and re-created, messing up the order of the brackets and who has won or not

I've tried to override these two methods

public void onSaveInstanceState(Bundle savedInstanceState) 

public void onRestoreInstanceState(Bundle savedInstanceState) 

to control what happens and hopefully restore the state that it was in before, but first I want to know if its possible to prevent the destroy and recreate stages from happening.

This is similar to when one wants to prevent an activity restart when a screen orientation change occurs by putting android:configChanges="orientation|keyboardHidden" in the manifest of an activity.

As soon as an activity goes to background, the system can destroy it at any time . Overriding onSaveIntanceState()/onRestoreInstanceState() is the right thing to do. You also need to deal with a simple case of pushing the Back button: your activity will also bi destroyed.

Having said that, it is strange that your activity is destroyed as soon as you push Home button. May be you have "Don't keep activities" option checked in Settings->Developer options on the 4.0.3 device?

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