Failure of using the activity life cycle in a notepad example

I got confused about using the life cycle of the life cycle in the example with notepad, in the example with notepad use the user model β€œedit in place”, inserting a new record into the onCreate method, keeping a constant state in the onPause method and keeping the source text in the onSaveInstanceState method. I am a J2EE programmer, I can not understand the logic described above. why not make things simple as shown below:

1. Do not add a new record to the onCreate method. 2. When the user clicks the BACK button, it is equal to clicking the save button in the editor, so insert or update in onPause if activity.isFinishing () is true. do not try to use data if activity.isFinishing () is not true. 3. Do not save the source text in the onSaveInstanceState method, it is not needed. If the activity is killed and vice versa, the restoration of the user entering the data in the editor will be adequate.

I think this logic is more traditional and natural. Maybe I do not understand the essence of the life cycle of an activity. Please provide your opinion.

thanks

Ljw

+4
source share
1 answer

The life cycle of an adroid application under various conditions (for example, switching screens, freezing, stopping, etc.) is described in an excellent video tutorial from Google . You can also refer to the slides of this conversation , in particular, the 16ff slide can be of great interest to you.

In any case, you are right in thinking that understanding the life cycle of an Android application is the key to coding for android.

+1
source

Source: https://habr.com/ru/post/1301658/


All Articles