Context란?
- "현재 사용중인 Application / Activity의 포괄적인 정보를 지닌 객체"
'포괄적인 정보'
-> 'Resource' 리소스 참조 (이미지, 레이아웃, 문자열 등)
-> 'Android 시스템 서비스' 사용
ApplicationContext? ActivityContext?
- Context는 ApplicationContext / ActivityContext 로 구분.
- Context의 수명에 따라 구분되어 사용
'ApplicationContext'
-> Application (어플리케이션)의 Life_Cycle에 종속적인 객체
-> 어플리케이션 실행 - 종료까지의 객체 정보를 참조할 수 있음
getApplicationContext() - Application객체가 Context형으로 반환
getApplication() - Application객체 반환, Context형 변수에 담아 사용 가능
'ActivityContext'
-> 현재 Activity (액티비티)의 Life_Cycle에 종속적인 객체
-> Activity.onDestroy() 발생 시 Context객체 소멸
getContext() - 액티비티, 서비스, 컨텐츠 프로바인더에서 사용
ActivityName.this - getContext()와 같은 Context반환,
(컨텐츠 프로바인더, 브로드캐스트 리시버는 this 불가 -> Context하위 클래스가 아니기에)
getBaseContext() -
View.getContext() - 해당 View(뷰)가 표시되는 Activity의 Context 반환
대체적으로 ApplicationContext를 많이사용, 'Null객체 예외 방지'
예외적으로 ActivityContext를 사용
-> 다이얼로그(Dialog) 표시, 레이아웃 인플레이션(Inflation)