Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I have a situation where i will have totally 5 activities. A,B,C,D,E. In activity stack there can be only three activities that is A,B,E or A,C,E or A,D,E so Activity A and E should be there in stack also other activities state should be saved so that i can get the activity as it was before.

to complete this task i have following queries

1.How to check whether a particular activity is there in stack already.

2. if it is there how to save its state so that i can replace the current activity with new activity.

3.How to replace one activity with another activity but keeping the state of the old activity.


I would be thankful to you if u give me the correct solutions
Posted

I'm not sure why you want to maintain the stack yourself, as android already keeps a stack of the activities: starting an activity pushes one on the stack, going back pops it from the stack.

I suppose deciding in activity A what will be your next activity b, C or D should do it. But then from your description I cannot tell if your use case allows for this decision.

about saving your activities state: check out Recreating an Activity
 
Share this answer
 
1. use ActivityManager to find running activities http://developer.android.com/reference/android/app/ActivityManager.html[^]
2. the activity states should be saved when the activity is paused. start a new activity with new state.
3. don't replace. just create a new one. or you can resume the previous activity and send changed data back by setResult. The pre-condition is you should use startActivityForResult not just startActivity
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900