I am calling startActivity to pass data from one activity to another using an activity's context in an external class.
This is one example of how I create the intent to be sent:
public static Intent createSearchIntent(Context context, Class<?> cls) {
Intent i = new Intent(ACTION_SEARCH, null, context, cls);
return i;
}
This is how the I start an activity:
mContext.startActivity(mIntent);
EDIT: Sorry, I was mistaken in what happens. The activity is not destroyed when I call startActivity, however the activity I am sending the intent to always has it's onCreate method called so I am guessing that a new instance of the activity is being created instead of returning to the paused/stopped one.
How would I be able to change it so that I can just return to the paused/stopped Activity?
The created activity object, if it had active listeners, or null if it has no event listeners. Creates a new activity if there are active listeners for it, using the specified name, activity kind, parent Id, tags, optional activity links and optional start time. public System.Diagnostics.Activity?
Android Activity startActivity (Intent intent, @Nullable Bundle options) Launch a new activity. Launch a new activity. You will not receive any information about when the activity exits.
The Intent constructor takes two parameters, a Context and a Class. The Context parameter is used first because the Activity class is a subclass of Context. The Class parameter of the app component, to which the system delivers the Intent, is, in this case, the activity to start.
There is a scenario that needs to add some more properties to the Activity object after it is created and before it gets started. The reason is the caller wants to avoid creating the objects need to set to the Activity before ensuring the Activity object is created.
This is when you need to use flags. For making a previously started activity to come back to the top of the stack you need to add the i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
flag to your intent and then start that activity-startActivity(i)
with 'i' being the intent name.
For a list of other flags have a look here.
Calling Activity B from Activity A doesn't by default does not destroy Activity A itself, what you see is Activity B displayed over Activity A, screen-overlapping. You can check by pressing Back
button.
It's the Activity lifecycle: http://developer.android.com/reference/android/app/Activity.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With