Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android
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 20:00pm

1 solution

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

Solution 1

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

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

  Print Answers RSS
0 OriginalGriff 384
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 CPallini 170
4 Shweta N Mishra 165
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 5 Jul 2013
Copyright © CodeProject, 1999-2014
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