Re-use previous activities?
Asked Answered
T

3

5

I have activities that are create and launched from menu options. However Ive noticed that this may mean that sometimes there are two or more copies of the same activity. So Im wondering if there's a way to see if another activity is already instantiated and then have the application switch to it or create a new one if its not instantiated.

Tyburn answered 16/2, 2010 at 22:3 Comment(0)
T
5

You can control some aspects of this with android:launchMode on the activity.

Timikatiming answered 16/2, 2010 at 22:41 Comment(0)
C
4

Programmatically try following:

    Intent intent = new Intent(contextActivity, NextActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    contextActivity.startActivity(intent);
Cornelius answered 10/8, 2012 at 10:21 Comment(1)
When providing code that solves the problem, it is best to also give at least a short explanation of how it works so that folks reading won't have to mentally parse it line by line to understand the differences.Amendatory
G
2

You can specify information regarding that in the android manifest. See activity element documentation. I believe that launchmode might control what you are after.

Gotthelf answered 16/2, 2010 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.