1

I have an activity with few fragments, out of which one fragment has a button which can be used to make a phone call from the app. Every thing is fine till this part, but what if I want to return the user to the same fragment in the app, with the same state as before the phone call, is it possible? I did have a look at one discussion on the stackoverflow. Here is the link

Link to answer for slightly similar question

It seems fine if I am making a call from activity and then return to that activity, but what can be done in case of fragments?

Community
  • 1
  • 1
  • Why dont you rely on the lifecycle events? OnPause() and onResume() especially. – Skynet May 22 '15 at 08:27
  • @Skynet If I get you right, you mean to say when a phone call is initiated from the fragment, the fragment enters paused state, I guess I would still be needing something like EndCallListener service to check if phone call has ended and then do something onResume. Right? –  May 22 '15 at 08:34

2 Answers2

0

You should think of an Activity as a wrapper for your Fragments, so you just need to keep track of your currentfragment in your Activity and it's not an accident that built-in FragmentManager does this for you. So you only need to make sure that you will reuse previous Activity and not starting a new one.

You should be able to do that with Intent.FLAG_ACTIVITY_CLEAR_TOP

simekadam
  • 7,334
  • 11
  • 56
  • 79
0

you can return same flagment.

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // save flagment position
}

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // set flagment position
}