Click here to Skip to main content
13,089,386 members (58,525 online)
Rate this:
Please Sign up or sign in to vote.
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 4-Jul-13 19:00pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

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);

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 5 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100