6

I have the following situation: one activity (DateActivity) calls another activity (ListActivity) when a button is clicked. That is working. However, every time the button is clicked it seems that a new copy of ListActivity is created. How do I make it resume the last ListActivity or create a new one if needed?

Note: I'm currently starting the ListActivity using startActivity(intent);

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
ludo
  • 1,456
  • 2
  • 14
  • 26
  • try this instead [Saving Activity state in Android][1] Hope this is helpful [1]: http://stackoverflow.com/questions/151777/saving-activity-state-in-android – Ehtesham May 25 '13 at 11:52

3 Answers3

7

not quite sure about your situation, but you can use intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(intent); to achieve your goal.

Longerian
  • 723
  • 5
  • 13
0

You should use the flag for the intent you are using.

Inten Intent i = new Intent(getApplicationContext(), YourActivity.class);
//this is what you are looking for
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

There are a lot of constants for the Intent object, for more information check the hint on your IDE when you star typing "FLAG_"

Re MiDa
  • 199
  • 1
  • 8
-2

Use startActivityForActivity() to launch ListActivity and use setResult() to return an Intent containing the state you want to return to next time. In DataActivity, onActivityResult() will receive this intent returned from ListActivity. The next time you launch ListActivity pass this (well traveled) intent to "resume" where you left off.

Sam
  • 86,580
  • 20
  • 181
  • 179