Reputation: 3
We are using the fragment without viewpage, just simply press the button to hide fragment A show fragment B or show A hide B, it will trigger the onHiddenChanged() function
But we have a argument here, one would like to run onPause() & onResume() directly in onHiddenChanged() just like running the activity
@Override
public void onHiddenChanged(boolean b) {
super.onHiddenChanged(b);
if (b) {
onPause();
} else {
onResume();
}
}
one was worry about changing the fragment lifecycle may cause the another problem, prefers not touching the onPause() & onResume()
@Override
public void onHiddenChanged(boolean b) {
super.onHiddenChanged(b);
if (b) {
//run onfragmenthide;
} else {
//run onframgnetshow;
}
}
my question is
Upvotes: 0
Views: 75
Reputation: 199795
No, you should absolutely not do that as you must not call into super.onPause()
and super.onResume()
unless the system is calling those methods.
Instead, extract your logic into two separate methods that you call in both places after the respective super
methods.
Upvotes: 1