2

My question is really short. I have a game which has a reset class that resets all the objects. If I understand it correctly I only need one instance of the game activity at the same time. Since if Android created multiple instances of the activity it would be a waste of resources.

Is the changing of launchMode in Android a way to achieve this. Is it safe to use launchMode="singleInstance" to achieve this?

Joakim Engstrom
  • 6,243
  • 12
  • 48
  • 67

4 Answers4

3

Check out the answer at Android singleTask or singleInstance launch mode? - which does a good job if explaining the documentation and refers on to an excellent blog / android app (at http://blog.akquinet.de/2010/02/17/android-activites-and-tasks-series-an-introduction-to-androids-ui-component-model/).

Community
  • 1
  • 1
Torid
  • 4,176
  • 1
  • 28
  • 29
2

I am not sure what launchMode="singleInstance" does, but you could achieve what you are trying to do by using the Singleton Pattern:

http://www.javabeginner.com/learn-java/java-singleton-design-pattern

nicholas.hauschild
  • 42,483
  • 9
  • 127
  • 120
2

I think singleTop is what you are looking for. singleTask and singleInstance should only be used in rare cases.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
2

If i'm right, singleTop will do the thing only if you have only 1 Activity so it's always on the top of the stack. Otherwise you can try to use Intent.FLAG_ACTIVITY_REORDER_TO_FRONT flag while sending an intent.

ernazm
  • 9,208
  • 4
  • 44
  • 51