본문 바로가기

카테고리 없음

Activity

Android 4대 컴포넌트 : Activity, Service, Broadcast Receiver, Content Provider

 

하나의 창을 띄어주며  setContentView를 통해 화면에 UI지정할 수 있다.

onCreate 

  • Activity 초기화 구간
  • setContentView를 통해 화면에 UI지정
  • 위젯 연결 사용(view binding,findViewbyId)

onPause() : 더이상 ui작용이 불가능한 상태(저장할 데이터가 있을 시 해당 구간에서 해야합니다)

 

Activity의 lifetime - onCreate() -> onDestory

Activity의 visible lifetime - onStart -> onStop

Activity의 foreground lifetime - onResume() -> onpPause()

 

lifecycle Callback Methods

onCreate() : Activity가 처음 생성될 때 호출, View 생성, Bundle 관리

onRestart() : Activity가 재실행될 때 호출됨

onStart() : Activity가 화면에 보이는 상태

onResume() : Activity가 화면에 보이며 사용자의 UI 작용이 가능한 상태 , Activity Stack에서 최상단에 위치하게 됨

 

onPause() 

1.Activity가 foregound 상태를 잃는 경우

2.Dialog가 아닌 Dialog 테마의 Activity가 뜨는 경우( android:theme="@style/Theme.AppCompat.Dialog")

3. Runtime Permission을 호출하는 경우

4. 시스템에서 파괴시킬 수 없는 상태 → 중요한 데이터는 해당 메소드 내에서 저장하자

 

onStop() : Activity가 화면에서 보이지 않는 상태 , 시스템에서 파괴시킬 수 있다.

 

onDestroy() :

1.Activity가 파괴되는 상태(시스템에서 파괴되기 직전 호출됨)

2.finish() 하는 경우

3. 메모리가 부족해서 안드로이드 시스템에서 파괴시키는 경우

4. 시스템에서 파괴시킬 수 있다.

 

Orientation Change시 콜백 메소드 호출 순서

onPause()

onStop()

onSaveInstanceState()

onDestroy()

onCreate()

onStart()

onRestoreInstanceState()

onResume()

728x90