안드로이드 개발

안드로이드 context란?

피커 2023. 5. 12. 21:27
728x90
반응형

Context?

 

이름에서 알 수 있듯이 응용 프로그램/개체의 현재 상태에 대한 컨텍스트입니다. 새로 생성된 개체가 진행 중인 작업을 이해할 수 있습니다. 일반적으로 프로그램의 다른 부분(활동 및 패키지/응용 프로그램)에 대한 정보를 얻기 위해 호출합니다.

getApplicationContext(), getContext(), getBaseContext() 또는 this(Application, Activity, Service 및 IntentService 클래스와 같이 Context에서 확장되는 클래스에 있는 경우)를 호출하여 컨텍스트를 가져올 수 있습니다.

컨텍스트의 일반적인 용도:

 

 

새로운 objects를 만들때 사용: Creating new views, adapters, listeners:

 TextView tv = new TextView(getContext());
 ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);

공통 리소스에 접근할때 사용: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:

 context.getSystemService(LAYOUT_INFLATER_SERVICE)
 getApplicationContext().getSharedPreferences(*name*, *mode*);

컴포넌트에 암시적으로 접근할때 사용 : Regarding content providers, broadcasts, intent

 getApplicationContext().getContentResolver().query(uri, ...);

 

 

Context 백서

 

Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

 

반응형