1

Say I have 2 fragments: A and B

Fragment A is on top. Now, I add fragment B keeping A in backstack.

Now when back button is pressed, B is removed and A comes on top.

Is there any callback method in A which gets called at this point?

Note: onResume is closely bound with activity, thus it is not called. Fragment's onResume() is called only when activity's onResume() is called.

seema
  • 991
  • 1
  • 13
  • 27
  • Yes. you can use Stack arraylist for it – Piyush May 14 '15 at 11:37
  • You need to add your both fragments in `Stack` arraylist from which you can push and pop up your desire fragment. Refer this link http://stackoverflow.com/questions/16189088/overlapping-hidden-fragments-after-application-gets-killed-and-restored – Piyush May 14 '15 at 11:42

3 Answers3

1

Sorry but there is no call back, as popToBackStack results to recreate fragments only in case of replace transaction and not in add.

Abhishek
  • 1,337
  • 10
  • 29
1

You may want to add OnBackStackChangedListener to your fragment manager and monitor BackStackEntryCount

getSupportFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {    
  public void onBackStackChanged() {
      Log.i(TAG, "back stack changed ");
      int backCount = getSupportFragmentManager().getBackStackEntryCount();

      }
    }
});

Once you get this trigger, you can pass a message from activity to fragment A as described in this article Deliver a Message to a Fragment or probably have an Observer in your Fragment observe an Observable in your main Activity

random
  • 10,238
  • 8
  • 57
  • 101
0

onViewStateRestored() is called when fragment is shown again.

seema
  • 991
  • 1
  • 13
  • 27