Most of what you read says that you should call onSaveInstanceState()on DialogFragmentto save its state, and then call onActivityCreated()and restore it there. Although this works, I found a problem:
If I have EditTextin my custom layout my DialogFragment AlertDialogand lets say that I enter my password. The password is masked and the cursor blinks after entering the last password. If I save the value entered in EditTextin onSaveInstanceState()and restore the state with onActivityCreated(), it will be restored, but the cursor moves to the beginning of what I just printed before the rotation, instead of remaining at the end.
However, if I restored what I saved using onCreateDialog(), first checking mine savedInstanceStatefor null, then my cursor will remain at the end after the last character typed in which it should be.
I wonder which path is correct, although I can see that both work fine and save the password when the rotation changes. The only thing that few people think is that the cursor moves to the beginning instead of remaining at the end in the case onActivityCreated().
source
share