티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.
What is 'Context' on Android?
안드로이드에서 'Context'란 무엇인가요?
문제 내용
In Android programming, what exactly is a Context
class and what is it used for?
안드로이드 프로그래밍에서 컨텍스트 클래스는 정확히 무엇이며 무엇에 사용됩니까?
I read about it on the developer site, but I am unable to understand it clearly.
나는 개발자 사이트에서 그것에 대해 읽었지만, 명확하게 이해할 수 없다.
높은 점수를 받은 Solution
Putting it simply:
간단히 말하면:
As the name suggests, it's the context of the current state of the application/object. It lets newly-created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity and package/application).
이름에서 알 수 있듯이 응용프로그램/객체의 현재 상태에 대한 컨텍스트입니다. 새로 생성된 개체가 무슨 일이 일어나고 있는지 이해할 수 있게 해줍니다. 일반적으로 프로그램의 다른 부분(활동 및 패키지/응용 프로그램)에 대한 정보를 얻기 위해 호출합니다.
You can get the context by invoking getApplicationContext()
, getContext()
, getBaseContext()
or this
(when in a class that extends from Context
, such as the Application, Activity, Service and IntentService classes).
getApplicationContext(), getContext(), getBaseContext() 또는 이것(Application, Activity, Service 및 IntentService 클래스와 같이 컨텍스트에서 확장된 클래스에 있는 경우)을 호출하여 컨텍스트를 가져올 수 있습니다.
Typical uses of context:
컨텍스트의 일반적인 용도:
- Creating new objects: Creating new views, adapters, listeners:
TextView tv = new TextView(getContext()); ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
- Accessing standard common resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:
context.getSystemService(LAYOUT_INFLATER_SERVICE) getApplicationContext().getSharedPreferences(*name*, *mode*);
- Accessing components implicitly: Regarding content providers, broadcasts, intent
getApplicationContext().getContentResolver().query(uri, ...);
새 개체 만들기:
표준 공통 리소스 액세스:
암시적으로 구성 요소에 액세스:
가장 최근 달린 Solution
What's Context
exactly?
Context가 정확히 뭐죠?
Per the Android reference documentation, it's an entity that represents various environment data. It provides access to local files, databases, class loaders associated to the environment, services (including system-level services), and more. Throughout this book, and in your day-to-day coding with Android, you'll see the Context passed around frequently.
안드로이드 참조 문서에 따르면, 다양한 환경 데이터를 나타내는 엔티티입니다. 로컬 파일, 데이터베이스, 환경과 관련된 클래스 로더, 서비스(시스템 수준 서비스 포함) 등에 대한 액세스를 제공합니다. 이 책 전체와 Android를 사용한 일상적인 코딩에서 컨텍스트가 자주 사용되는 것을 볼 수 있습니다.
From the "Android in Practice" book, p. 60.
"Android in Practice" 책 60쪽.
Several Android APIs require a Context
as parameter
일부 Android API에서는 매개 변수로 컨텍스트가 필요합니다.
If you look through the various Android APIs, you’ll notice that many of them take an android.content.Context
object as a parameter. You’ll also see that an Activity or a Service is usually used as a Context
. This works because both of these classes extend from Context
.
당신이 다양한 안드로이드 API들을 훑어보면, 당신은 다음과 같이 될 것이다. 그들 중 많은 사람들이 안드로이드 콘텐츠를 가지고 있다는 것을 알아보세요.컨텍스트 개체를 a 매개 변수 또한 활동 또는 서비스가 일반적으로 다음과 같이 사용된다는 것을 참조하십시오. 맥락. 이는 두 클래스가 모두 컨텍스트에서 확장되기 때문에 작동합니다.
출처 : https://stackoverflow.com/questions/3572463/what-is-context-on-android
'개발 > 안드로이드' 카테고리의 다른 글
안드로이드에서 'Context'를 정적으로 가져오는 방법 (0) | 2022.11.29 |
---|---|
loadurl을 호출할 때 Android 웹 뷰가 브라우저를 실행합니다. (0) | 2022.11.28 |
리사이클러 뷰에 해당하는 addHeaderView가 있습니까? (0) | 2022.11.27 |
[안드로이드/android] back key 두번 눌러서 activity 종료 시키기 (0) | 2018.10.26 |
[안드로이드/android] WebView cache, cookie 삭제하기 (0) | 2018.10.26 |