简体   繁体   中英

Don't call onDestroy() of the parent Activity after calling startActivity()?

I have an Activity with a lot of fragments transactions in it, and sometimes my users need to open the preferences Activity for a few seconds. I do it like this :

Intent preferencesIntent = new Intent(this, PreferencesView.class);     
this.startActivity(preferencesIntent);

Each time I do this, onDestroy() of my main Activity is called. So when my user are coming back, the main Activity is in it initial stage. But I would like the main Activity to be like when they leave it.

I know that I should save/restore my data and just let the Activity recreate itself. But this would be very complicated, and my users are in my main Activity most of the time.

So is there a way to tell Android not to kill my main Activity while it is not visible?

Thank you in advance!

You've alreay written the answer: save/restore state. This is how android works.

Your activity can be destroyed configuration change or something else.

You can't prevent Android to stop an Activity. The only way I see is to load the preferences in a Fragment in the main Activity.

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