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.

Eno
  • 10,730
  • 18
  • 53
  • 86

3 Answers3

5

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

Erich Douglass
  • 51,744
  • 11
  • 75
  • 60
4

Programmatically try following:

    Intent intent = new Intent(contextActivity, NextActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    contextActivity.startActivity(intent);
mizim
  • 41
  • 1
  • 4
    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. – Fluffeh Sep 28 '12 at 10:37
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.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82