Android: Activity life cycle

Activities have the above life cycle. The activity will call the appropriate method according to this lifecycle and will generally execute in the following order:

onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestory()

In some cases, the onRestart() method is called. Also, onStop() and onDestroy() may not be called.

Method Explanation Next Method
onCreate() Invoked when an activity is created. Used to initialize the user interface. onStart()
onRestart() Called just before the activity stopped and then restarted onStart()
onStart() Called just before the activity is shown to the user. onResume() or onStop()
onResume() Called just before the activity interacts with the user. onPause()
onPause() Invoked when another activity is shown. This method is suitable for handling data storage, thread stop, and so on. onResume() or onStop()
onStop() Invoked when the activity is no longer visible to the user. If there is not enough memory, the onStop() method may not be called. onRestart() or onDestroy()
onDestroy() Called when the activity is destroyed. The finish() method is called at the same time. It is also called when the system removes the activity to free up memory. None

OnUserLeaveHint(): which is executed when the user presses the home key

The Activity class contains the onUserLeaveHint() method, which is called when the user presses the home key. By overriding this method, the user can execute the desired action when the user presses the home key.

After the onUserLeaveHint() method is called, the Activity’s onPause() method can be called to handle data storage, thread stop, and so on.

Share This Post

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다

Latest Post