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?
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.