OnCreate vs. onResume / onRestart bevhavor regarding member variables

When I open an action, I know that I can initialize the material in the onCreate function.

But what is the behavior of the OnResume and onRestart functions? When are these features called?

In particular: I initialize the local member variable in the onCreate function auiqring reference to the global object. Now, when the user is interrupted, for example, on a call, activity can be closed. Later, when the user returns to my opinion, what is the status of an already initialized variable? Should I reinitialize everything in the onResume / onRestart functions? So what will be the functional difference opposite to onCreate?

+6
source share
2 answers
  • onCreate : activity launched for the first time. Here you can initialize your materials.
  • onResume : the user returns to activity after another action comes to the fore. ( onPause )
  • onRestart : The user proceeds to activity after he is no longer visible ( onStop ).

You can see the full life cycle of action documentation . Your activity stuff will only be lost when you call onDestroy , which happens when you complete it, or when it is destroyed by the system (i.e. when applications with a higher priority need memory)

+6
source

Suppose that the dialog is initiated from your current activity, the main window (Activity) will go into the onPause state. After you activate the activity in the background (suppose you click the home button). The action will go into onPause state.

+1
source

All Articles