0

In essence my app will have 4 activities. A,B,C,D. A goes to C A-->C

where C might want to go to D, back to C, back to D. Or anywhere within this path. B <--> C <---> D

I have reason to believe this is spawning a new activity each time, which is resulting in multiple stacks of the same activity. For instance moving back and forth between C and D 3x would result in 3 live activities for C and 3 for D.

The question is how can I accomplish this to where if a new activity needs to be created it will, yet if one has already been created, it will move to displaying the previous spawn. C(1)-->D(1)-->C(1) instead of C(1)-->D(1)-->C(2)

Or even more simply what if I wanted to go back and forth between A and B with buttons but not create an ever increasing stack of instances?

Steven Akerfeldt
  • 589
  • 6
  • 15

2 Answers2

3

I think you are looking for FLAG_ACTIVITY_SINGLE_TOP. Please see this answer:

https://stackoverflow.com/a/3283118/1369222

Community
  • 1
  • 1
  • I tried this and it has made zero effect. I used Intent i = new Intent(this.getApplicationContext(),MyActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(i); At every point where the activities are started. What did I do wrong? – Steven Akerfeldt Dec 12 '12 at 15:50
0

I think what you are looking for is

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

where you can flag your activity to launch only a single instance or a new task

n3utrino
  • 2,319
  • 2
  • 21
  • 31