StartActivity creating a new instance of Activity every time

I call startActivity to transfer data from one activity to another using the activity context in the outer class.

This is one example of how I create an intent to send:

public static Intent createSearchIntent(Context context, Class<?> cls) { Intent i = new Intent(ACTION_SEARCH, null, context, cls); return i; } 

This is how I start the action:

 mContext.startActivity(mIntent); 

EDIT: Sorry, I was wrong about what was going on. Activity is not destroyed when I call startActivity, however the activity that I send the intent always has the onCreate method, so I assume that a new instance of the action is created, and not returning to the paused / stopped.

How can I change it so that I can just return to a paused / stopped action?

+6
source share
2 answers

This is when you need to use flags. To make a previously started operation, to return to the top of the stack, you need to add the i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); flag i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); in your intention, and then start this activity - startActivity(i) , where "i" is the name of the target.
A list of other flags looks here .

+8
source

Invoking Activity B from Activity A by default does not destroy Activity A itself, what you see is Activity B displayed above Activity A, the screen overlapping. You can check by clicking the Back button.

This is the activity lifecycle: http://developer.android.com/reference/android/app/Activity.html

+4
source

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


All Articles