tags:

views:

31

answers:

3

I'd like the activity stack for my app to contain multiple instances of the same activity, each working on different data. So I'd have activity A working with data a, b, c and d in my activity stack ad I'd have 4 instances of activity A that I'd call A(a), A(b), A(c) & A(d). I'd also like to arrange it so that if the user asks to work with data c again then it won't start a new activity, but rather will just bring the already running activity A(c) to the front.

Any suggestions on the best way to achieve this?

A: 

I'm not sure you can do it the way you have it described because fiddling with the activity stack like that is not supported AFAIK.

What you could do instead is just use a tab based activity. Each tab could be another instance of activity A working on a different dataset.

smith324
A: 

I agree with Falmarri (comment), you cant "switch between activities" in the way you are describing. You can however store that data somewhere (file, database, service, global variable, ext.). Where you choose to store that data (a, b, c, d) is up to you and depends on what kinds of functionality you need your data to have.

As for how you "switch" from one to the other, that is somewhat easier than you might think. you dont actually have to "switch" from one activity to the other, you can just swap our all the data. its is perfectly legal (though not always recommended) to have your entire app exist in ONE activity, and merely switch layouts over and over.

My suggestion would be to swap out the data within one activity. you could even specify which data set you want to load initially in your intent filter.

mtmurdock
A: 

So I'd have activity A working with data a, b, c and d in my activity stack ad I'd have 4 instances of activity A that I'd call A(a), A(b), A(c) & A(d).

That will happen by default.

I'd also like to arrange it so that if the user asks to work with data c again then it won't start a new activity, but rather will just bring the already running activity A(c) to the front.

I do not believe that is possible unless you create distinct activities for each letter.

CommonsWare