Reputation: 2383
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!
Upvotes: 4
Views: 1875
Reputation: 3686
You've alreay written the answer: save/restore state. This is how android works.
Your activity can be destroyed configuration change or something else.
Upvotes: 2
Reputation: 11
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.
Upvotes: 1