I wanna get notified when my Fragment reenters before a shared element transition happens, like I can do with the Activities onActivityReenter
method. Is there a similar way I can do this for fragments?
While there's no onActivityReenter
method in Fragment
, what I've found myself doing is calling a public method on my Fragment
from the Activity
.
Define a public method in your Fragment
class:
public void onReenter(Intent data) {
// Do whatever with the data here
}
Then just call it when onActivityReenter
is called in your Activity
:
@Override
public void onActivityReenter(int resultCode, Intent data) {
super.onActivityReenter(resultCode, data);
ItemFragment fragment = (ItemFragment) getSupportFragmentManager().findFragmentByTag(ITEM_TAG);
if (fragment != null) {
fragment.onReenter(data);
}
}