ludo
ludo

Reputation: 1466

How to resume an activity when calling it from an Intent

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

Upvotes: 6

Views: 13554

Answers (3)

Re MiDa
Re MiDa

Reputation: 209

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_"

Upvotes: 0

Longerian
Longerian

Reputation: 723

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

Upvotes: 7

Sam
Sam

Reputation: 86948

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.

Upvotes: -2

Related Questions