I have a TabHost
with two tabs
in it. The first time I switch to the second tab
the onResume()
method of my second's tab's activity
invoked. Then I have an AlertDialog
shown and after it disappears the 'onResume()' method isn't called but I really wait for it. I presume that invocation of 'AlertDialog' triggers 'onPause()' method and the 'onResume()' should be called before 'Activity' is actually shown and ready for interaction with user. But in face 'onPause()' isn't called when I switch back to the first tab
which is another activity
.
Can you advice why the 'onPause()' and 'onResume()' methods aren't called and what methods are called after showing an 'AlertDialog' or switching between tabs
?
When you create a TabHost to hold Activities, the childrens inside it can't manage their own lifecycled methods (onResume, onPause, onCreated, etc), and the parent (the holder) must do all the managements. I've implemented this behavior by overwriting onPause and onResume in the holder (the Activity that defines the tabhost), like this:
@Override
public void onPause() {
super.onPause();
try {
mlam.dispatchPause(isFinishing());
} catch (Exception e) {}
}
@Override
public void onResume() {
super.onResume();
try {
mlam.dispatchResume();
} catch (Exception e) {}
}
Where "mlam" is the LocalActivityManager instance. With it, I think that your onResume/onPause methods gonna be triggered. Hope that this helps you in some way.
@mthama's answer worked perfectly fine and had declared LocalActivityManager as a local variable at the Tabhost level. However if I wanted just one of the onResume() on a specific tab to fire, I did as follows.
protected void onResume() {
super.onResume();
try {
if(mLocalActivityManager != null){
TabActivityOne tabActivity1 = (TabActivityOne) mLocalActivityManager.getActivity("tabId1");
if(tabActivity1 != null){
tabActivity1.onResume();
}
}
} catch (Exception e) {
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With