How to resume an action when called from an intent

I have the following situation: one action (DateActivity) causes another activity (ListActivity) when the button is clicked. It works. However, each time you click the button, a new copy of ListActivity is created. How to make it resume the last ListActivity or create a new one if necessary?

Note. I am currently starting ListActivity using startActivity(intent);

+6
source share
3 answers

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.

+5
source

You must 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 many constants for an Intent object, for more information check the tooltip on your IDE when you type the asterisk โ€œFLAG_โ€

0
source

Use startActivityForActivity() to start ListActivity and use setResult() to return an intent containing the state that you want to return next time. In DataActivity, onActivityResult() will receive this intent returned from ListActivity. The next time you start ListActivity, go through this (well-moved) intention to โ€œresumeโ€ where you left off.

-2
source

Source: https://habr.com/ru/post/915579/


All Articles