Life cycle of action?

I think my ideas about activity life cycle and ligaments
a little confused, can you help me?

Suppose a user opens activity A on the main screen,
activity A β€œtriggers” activity B , which fills the screen.
On this event, onSaveInstanceState() calls activity A , then onPause() and onStop() .
Since the system has too many applications running on the system,
andorid decides to kill activity hosting process A.

When the user proceeds to activity A , onCreate () is called as soon as possible, use the package (installed during the last call to onSaveInstaceStae ()) to restore the state. then onStart() , onRestoreInsanceState()
and onResume() ,
I'm right?

Then let's assume that the user presses the back key to exit activity A
onPause() , onStop() and onDestory() are called sequentially by activity A (the call to onDestroy() can be delayed, though) onSaveInsanceState() should not be called in this script.

When the user reopens activity A later, then the packet passed to onCreate () is null, right?

Now suppose the user rotates the screen onSaveInsanceState() , onPause() , onStop() , onDestroy() are then called onCreate() with the bundle set by the last call to onSaveInsanceState() ,
and then onStart () and onRestore (). I'm right?

I suppose that:

when the user creates activity, the packet passed to onCreate() is always zero, and onRestoreState() never called, but when the system creates it, for example, when it killed activity due to low memory or due to the rotation event passed the bundle is the one that was set by the last call to onSaveInstanceState ().

Did I understand correctly?

thanks and sorry for my bad english.

PS: I think that onRestoreInstanceState() is passed, the same package is passed onCreate() , but usually the state is restored using onCreate() .

+6
source share
3 answers

An interesting question - I never thought about it.

Take a look at the documentation onCreate() and onSaveInstanceState() .

Answers at least to your question that the Bundle will be sent to onCreate() .

Unfortunately, there is no exact definition by which the onSaveInstanceState() event is onSaveInstanceState() , but I think that it is onSaveInstanceState() by default in all relevant situations (no matter what they may be ...), but you can learn about some situations ( e.g. by rotating the screen) by placing Log.i () in the LogCat.

0
source

onRestoreInstanceState () passes the same package that is passed to onCreate () correctly, and the system restarts the action by calling onCreate (), and also calls onRestoreInstanceState (), the package will be null if get from onCreate () when activity is first started .

0
source

Since there are too many applications running on the system, andorid decides to kill the hosting process A.

This is a very common situation. In addition, you can emulate this action using the developers option.

enter image description here

In this case, every action that has been moved to the background will be automatically destroyed.

About the package in OnCreate.

I can only get from my memory two cases where OnCreate will be called with a non-zero Bundle. First - described above. The second case is a screen rotation.

When you launch the Android Android application

  • Oncreate
  • Onstart
  • onResume

After that, it allows you to rotate the screen. Android will cause

  • onSaveInstanceState
  • Onpause
  • Onstop
  • Ondestroy
  • Oncreate
  • Onstart
  • onRestoreInstanceState
  • onResume

You can find more information on recreating.

0
source

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


All Articles