Android/개념 및 정보
[Context] Context란 - (getApplicationContext와 this 차이점)
Taehyung Kim, dev
2020. 7. 17. 10:51
728x90
Context의 종류
안드로이드에는 두 종류의 context가 있습니다.
Applicaiton context : 어플리케이션 자체와 연동되는 것이므로, 어플리케이션의 life cycle이 지속되는 동안 동일한 객체입니다. 즉, 어플리케이션을 종료 후 다시 실행시킬때에만 바뀌는 것이지요.
Activity context : 액티비티와 연동된 것이므로, 그 액티비티를 파괴시키고 다시 시작시키면 activity context도 바뀝니다(한 개의 어플리케이션 내에는 여러 액티비티를 넣을 수 있지요).
this와 getApplicationContext()의 차이점
this :activity의 context
getApplicationContext() : application의 context
getBaseContext(), getApplication() ?
this = getBaseContext() = Activity Context
getApplicationContext() = getApplication() = Application Context
728x90