Does android replay last events after rotating the device


#1

In CrimeFragment, i am using android.app.Fragment with a LinearLayout that contains one android.widget.EditText inside it and i dont have landspace layout folder. A android.text.TextWatcher is added to the EditText via addTextChangedListener. Say i enter a letter “a” into the EditText and i rotate the android device. I would expect the existing Fragment to be completly destroyed and a new instance of Fragment to be created. Also, i expect the EditText to be empty in the new Fragement. But to my surprise, following happens:-

1.Both Fragment and its containing Activity are completely destroyed
2. A new instance of Fragment and Activity are created. So far good. this is per my expectation.
3. BUT, the last events on EditText are replayed. The last events were beforeTextChanged() and onTextChanged(). How is this possible? If a new instance of fragment is created, this would imply a new instance of EditText is created, then who is reposible for replaying the last events on EditText?


#2

It’s not replaying the events. It’s:

1- Stashing the text from the EditText in savedInstanceState
2- Destroying everything (including the EditText)
3- Recreating everything (including a new EditText)
4- Putting the stashed text into the newly created EditText

That last step triggers the events you are seeing on your TextWatcher.