Bobby_th February 2016

Go back to another or old Activity from a fragment in an activity

I have looked for this but, can't seem to find the answer that I need.

So, my scenario is, I have activityA that starts activityB using Intent. Then activityB sets up some values in a bundle and starts a fragment using fragment manager. Now, I want to go back to activityA when a button is click. I also want to pass some variables from the Fragment to activityA. How do I do this?

Currently, I just start just the activityA again by using intent with some bundle of data passed in from the fragment. This is not good, because I am restarting activityA again. I just want to go back like using OnResume() or something similar, so that my old data is still there in activityA again.

Thanks

Answers


Crew Peace February 2016

You can either call finish like you would do from an Activity but like so:

getActivity().finish();

Or you can start the Activity and recall the previous one from the stack:

Intent i = new Intent(getActivity(), activityA.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

Post Status

Asked in February 2016
Viewed 3,260 times
Voted 14
Answered 1 times

Search




Leave an answer