Coordination of interaction: onStop and onResume

I have two activities. One loads all the rows from the database, and the other saves the database. When I have a second save in onStop and the first push of data in onResume, they do it out of order (the first resumes and then the second saves). I managed to fix this by putting the save data in onPause, but why did this happen? Was this the cleanest way to do this?

+3
source share
2 answers

Performing a save in the first actvity onPause should be fine.

You have found that the lifetime of the foreground event occurs between the call to onResume () until the corresponding call to onPause (). During this time, the activity before all other actions on the screen and interacts with the user.

When you start the second action, onPause is called on the first, and then the interactive control switches to the second, while onStop on the first call will be somewhat in the background.

This improves responsiveness and gets new activity in front of the user as soon as possible. Therefore, you should try to make your onPause implementation as fast and efficient as possible.

For more information on the life cycle, see the following Android docs http://developer.android.com/guide/topics/fundamentals.html , but what you find should work fine for you.

+5

:

Activity ,

onPause() - , , . , , ,

0

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


All Articles