getBaseContext() vs getApplicationContext(), getContext() vs getBaseContext() vs getApplicationContext() vs this

CODEDRAGON Development/Android

반응형


 

 

getBaseContext() vs getApplicationContext()

구분

설명

ContextWrapper.getBaseContext()

·       Activity Context

·       생성자나 Context에서 기본 설정 된 Context

·       앱 종료 후 메모리 유지를 피하기 위해서 getBaseContext를 사용

getApplicationContext()

·       Service Context

·       어플리케이션의 종료 이후에도 활동 가능한 글로벌한 Application Context

 

 

 

getContext() vs getBaseContext() vs getApplicationContext() vs this

구분

설명

View.getContext()

·       현재 실행되고 있는 Viewcontext return 하는데 보통은 현재 활성화된 activity context가 됩니다

Activity.getApplicationContext()

·       어플리케이션의 Context return됩니다.

·       현재 activiy context 뿐만 아니라 application lifeCycle에 해당하는 Context가 사용됩니다

ContextWrapper.getBaseContext()

·       자신의 Context가 아닌 다른 Context access하려 할 때 사용합니다.

·       ContextWrapper getBaseContext()를 경유해서 Context를 참조할 수 있습니다

this

·       View.getContext()와 같습니다

 

 


반응형