简体   繁体   中英

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM