Click here to Skip to main content
15,894,212 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This might be a simple question, I have one android app in which I have several pages. Now suppose in starting I am working on page-1 . then I switch over to page-2. then to page-3. meanwhile I again want to use page-1. so I use startActivity(intent) to go back to that page. But what happens is page-1 is created once again i.e. a new instance.

Suggest me how to use that previously stacked instance of page-1 without making new instance.

Also note that pg-1 is home page of app so I cannot use finish() method while going to page-2.
Posted

1 solution

Hi,
The problem is caused due to launchmode. You are using standard mode if you've not changed anything. Therefore, an instance will always be created in standard mode. One solution is using tab format, thus you can switch between tabs and activities. The other solution is keeping the values of variables in Sharedpreferences and relaunch in the new activity(by the way you could finish the previous activities by writing 'Activityname.this.finish()' or you could write android:launchmode="singleTask" to all your activity to have only one activity at a time)
or:
http://stackoverflow.com/questions/7202612/how-to-go-back-to-3rd-previous-activity-in-android[^]

:
you can use finish() in every activity as you proceed or you can start your first activity with this flag FLAG_ACTIVITY_CLEAR_TOP and it will clear all the top activity of your first activity and it will bring your first activity on top.Use like this:

Intent intent = new Intent(this, yourFirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
 
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