Android – how do I listen to fragment Backstack pop only?
•
Android
I want to know when the clip pops up from the background
My code is as follows
private void setupChildFragmentPopListener() {
getChildFragmentManager().addOnBackStackChangedListener(
new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
// Do whatever I want
}
});
}
However, this code is triggered when adding and pop fragments. How can I just listen to popular fragments? Or filter out its method in the onbackstackchanged () function, if it is not pop?
resolvent:
You can keep the count of Backstack entries and compare them every time you call onbackstackchanged()
private void setupChildFragmentPopListener() {
getChildFragmentManager().addOnBackStackChangedListener(
new FragmentManager.OnBackStackChangedListener() {
@Override
public void onBackStackChanged() {
int backCount = getChildFragmentManager().getBackStackEntryCount();
}
});
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码