Skip to content

Android:ActivityLifeCycle

Android의 Activity의 생명주기에 대한 내용 정리.

About

Activity_lifecycle.png

In general the movement through an activity's lifecycle looks like this:

Method

Description

Killable?

Next

onCreate()

Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one.
Always followed by onStart().

No

onStart()

-

onRestart()

Called after your activity has been stopped, prior to it being started again.
Always followed by onStart()

No

onStart()

-

onStart()

Called when the activity is becoming visible to the user.
Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.

No

onResume() or onStop()

-

-

onResume()

Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it.
Always followed by onPause().

No

onPause()

-

-

onPause()

Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns.
Followed by either onResume() if the activity returns back to the front, or onStop() if it becomes invisible to the user.

Pre-HONEYCOMB

onResume() or onStop()

-

onStop()

Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.
Followed by either onRestart() if this activity is coming back to interact with the user, or onDestroy() if this activity is going away.

Yes

onRestart() or onDestroy()

onDestroy()

The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

Yes

nothing

Resume and Pause

onPause() 함수는 Activity 위에 다른 Activity 가 올라오거나 하여 focus 를 잃었을 때 불린다. onResume() 함수는 focus 를 다시 얻었을 때 불린다. 예를 들어 폰의 alarm 이 울리거나 전화가 오는 경우 onPause() 함수가 불린다.

Start and Stop

onStop() 함수는 Activity 가 완전히 화면을 벗어날 때 불린다. 예를 들어 홈키를 눌러 홈화면으로 이동하거나 전화가 와서 화면을 완전히 덮는 경우 불린다. onStart() 함수는 Activity 다시 화면이 다시 돌아 올 때 불린다.

선택 방법

만약 자신의 Activity 위에 다른 Activity 가 올라왔는데 화면을 전부 채우지 않았을 때 작업을 계속 하고 싶다면 onStart()/onStop() 함수에 작업 시작/종료 를 구현하면 되겠고 Activity 가 focus 를 잃으면 무조건 작업을 종료해야 하는 경우 onResume()/onPause() 함수에 작업 시작/종료를 구현하면 되겠다.

See also

Favorite site

References


  1. Android_activity_lifecycle_kor.pdf