I have a situation where onDestroy
fires immediately after onSaveInstanceState
.
Will the runtime environment (dalvik) retain a copy of the bundle
set in onSaveInstanceState
, and pass it back into onCreate
?
Or, is the bundle
null/void?
If the bundle does end up being destroyed
, is persistence of the "view"/"gui"-state to be done instead in onPause
(or some other lifetime method)?
Update (specific problem driving my question)
public class CView : MXFragmentView<CViewVM>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle)
{
base.OnCreateView(inflater, container, bundle);
_inflater = inflater;
_container = container;
_bundle = bundle;
...
}
public override void OnSaveInstanceState(Bundle outState)
{
Log.Info(TAG_APP, "CView.OnSaveInstanceState(): BEGIN");
base.OnSaveInstanceState(outState);
outState.PutInt(SaveStateParams.CurrentTabIndex, _tabHost.CurrentTab);
}
public override void OnDestroy()
{
Log.Info(TAG_APP, "CView.OnDestroy(): BEGIN");
base.OnDestroy();
}
}
I/APP_TAG(6398): CView.OnSaveInstanceState(): BEGIN
I/APP_TAG(6398): CView.OnDestroy(): BEGIN
W/Bundle(6398): Key android:view_state expected Bundle but value was a android.util.SparseArray. The default value <null> was returned.
W/Bundle(6398): Attempt to cast generated internal exception:
W/Bundle(6398): java.lang.ClassCastException: android.util.SparseArray cannot be cast to android.os.Bundle
W/Bundle(6398): at android.os.Bundle.getBundle(Bundle.java:1142)
W/Bundle(6398): at android.app.LocalActivityManager.dispatchCreate(LocalActivityManager.java:455)
W/Bundle(6398): at CView.n_onCreateView(Native Method)
W/Bundle(6398): at CView.onCreateView(CView.java:60)
I've been familiarizing with post Saving Android Activity state