공유 설정을 읽는 것에 대한 질문 : this 및 this을 읽었습니다. 그러나 SharedPreferences에 액세스하려면 Context가 필요합니다. 컨텍스트없이 SharedPreferences에 액세스하는 방법을 알고 싶습니다. 미리 감사드립니다.컨텍스트없이 SharedPreferences에 액세스
5
A
답변
5
먼저 ApplicationContext (this)를 검색하고 SharedPreferences를 얻기 위해 해당 컨텍스트를 사용하여 문제를 해결합니다. K-ballo에게 감사드립니다.
0
응용 프로그램 클래스 :
import android.app.Application;
import android.content.Context;
public class MyApplication extends Application {
private static Context mContext;
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
}
public static Context getAppContext() {
return mContext;
}
}
는 AndroidManifest를에서 응용 프로그램을 선언 :
<application android:name=".MyApplication"
...
/>
사용법 : 단순히 _can't_하지만 한
PreferenceManager.getDefaultSharedPreferences(MyApplication.getAppContext());
관련 문제
- 1. 컨텍스트없이 리소스에 액세스
- 2. sharedPreferences에 저장
- 3. datepicker를 sharedpreferences에 저장하는 방법
- 4. SharedPreferences에 문자열 배열 저장
- 5. sharedpreferences에 배열 저장
- 6. 번들을 SharedPreferences에 저장
- 7. Spinner 선택을 SharedPreferences에 저장
- 8. 첫 번째 활동을 표시하기 전에 SharedPreferences에 액세스 하시겠습니까?
- 9. 다른 Android 기기에서 SharedPreferences에 액세스 할 때의 성능 차이를 설명하십시오.
- 10. 모든 활동에 액세스 할 수있는 SharedPreferences에 데이터 저장
- 11. 컨텍스트없이 안드로이드의 시스템 환경 설정하기
- 12. mootools에서 컨텍스트없이 .fireEvent()를 호출
- 13. Android : JSON 데이터를 SharedPreferences에 저장
- 14. 사용자 지정 DialogPreference에서 SharedPreferences에 저장
- 15. 글꼴 크기가 SharedPreferences에 저장되지 않습니다.
- 16. radiogroup의 selectedindex를 sharedpreferences에 저장하는 방법
- 17. json을 사용하여 sharedpreferences에 데이터를 저장합니다.
- 18. Robolectric의 SharedPreferences에 대한 테스트 데이터 제공
- 19. ASP.NET MVC - HTTP/요청 컨텍스트없이 경로 생성
- 20. 컨텍스트없이 하나의 객체를 다른 객체에 연결
- 21. 환경 설정을 SharedPreferences에 저장하지 않으려면 어떻게해야하나요?
- 22. "JSON.stringify"데이터를 SharedPreferences에 저장하는 것이 좋지 않습니까?
- 23. INT를 SharedPreferences에 저장할 수없는 이유는 무엇입니까?
- 24. SharedPreferences에 GPS 위치를 저장하는 방법 Android
- 25. 수퍼 유저로 전환하면 모든 공유 응용 프로그램 sharedpreferences에 액세스 할 수 있습니까?
- 26. ERROR/libEGL (206) : 현재 컨텍스트없이 OpenGL ES API를 호출하십시오.
- 27. 응용 프로그램 컨텍스트없이 스프링 보안 필터를 사용하는 방법?
- 28. CTLine 또는 NSAttributedString - 그래픽 컨텍스트없이 이미지 경계를 가져 옵니까?
- 29. xml에서 다른 xml 로의 액세스?
- 30. uriworkermap.properties jQuery를 사용하여 IIS와 Tomcat 루트 (컨텍스트없이)에서 하나의 tomcat 사이트를 실행합니다.
하면 응용 프로그램이 실행되는 동안 사용할 수있는 _Application_Context_가 있습니다 ... –
수 없습니다. 문맥이 필요합니다. – Guardanis
왜 그런 식으로해야하는지에 대해 자세히 설명 할 수 있다면 더 많은 것을 도와 드릴 수 있습니다. – Erol