Open ursusursus opened 6 years ago
Okay now I noticed that savedViewState always empty in onBindView, and only non-empty if I put something in onSaveViewState
@Override protected void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) {
super.onRestoreViewState(view, savedViewState);
Bundle dialogState = savedViewState.getBundle(SAVED_DIALOG_VIEW_STATE_TAG);
if (dialogState != null && dialog != null) {
dialog.onRestoreInstanceState(dialogState);
}
}
@Override protected void onSaveViewState(@NonNull View view, @NonNull Bundle outState) {
super.onSaveViewState(view, outState);
if (dialog != null) {
Bundle dialogState = dialog.onSaveInstanceState();
outState.putBundle(SAVED_DIALOG_VIEW_STATE_TAG, dialogState);
}
}
This works well for all of view hierarchy, no need to futz about with individial views
Hi
When config change the controller not destroyed and onSaveInstanceState
, onRestoreInstanceState
not called.
So, if you use MVP your presenter still alive after config change and you can bind data to UI
Okay, but I do think this is a bug
I dont think restoring view focus or position of cursor in edittext should be users responsibility + dialog fragment handles this
Hi, restoring state of controller works (i.e. after rotation dialog stays (comes up again) shown)
However if I put a view inside my alert dialog (usecase: title, edittest, cancel button, ok button) then the text inside edittext is not restored after config change. DialogFragment does this, so I presume this is a bug
I looked around the source and the problem seems to be that you do save the dialog instance state at line 237. However you never restore it. Looking at the DialogFragment is should be after the
dialog.setOwnerActivity(getActivity()); dialog.setCancelable(cancelable); dialog.setOnShowListener(this); dialog.setOnCancelListener(this); dialog.setOnDismissListener(this);
combo of setters.
I would restore it myself, but you made onBindView private and onCreateView final
(Btw looking around with debugger, onRestoreInstance state was never called for me after rotations, is this also as designed?)
Workaround for now is to manually do it via