Reputation: 3029
I have an activity which shows an image (ViewCollection.java). I want to only create it once, then re-use that instance to further show more images from different calls (The activity is expensive to initialize). So far, I launched the activity like this:
Intent i = new Intent(this, ViewCollection.java);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
And all activity calls from the ViewCollection activity are also called by the same method. But despite this, the activity keeps getting destroyed when I start other activities from it... What can I do to fix this?
*PS: The activity is set to "standard" launch mode
Upvotes: 2
Views: 2492
Reputation: 24820
Set the activity launchmode to singletop or set the flag FLAG_ACTIVITY_SINGLE_TOP
.
Handle the intent in onNewIntent()
You can get further details here
Edit: Though if back key is pressed on the activity or configuration changed since last time you entered the app, the activity will still be recreated
Upvotes: 3
Reputation: 2289
Try getting rid of this line
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
that way you can go back to the previous activity
Upvotes: 0