1 단계 - 확장 Application 클래스
import android.app.Application;
import android.content.Context;
/**
* This class is created automatically when the app launches.
* It is used to provide an application-level context for the SQLiteOpenHelper
*/
public class ApplicationContext extends Application
{
private static ApplicationContext instance;
public ApplicationContext()
{
instance = this;
}
public static Context getContext()
{
return instance;
}
}
2 단계 -이 응용 프로그램 클래스가를 사용되도록 매니페스트를 업데이트
<application android:name="ApplicationContext"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
3 단계 - 싱글을 구축 SQLdataHelper 앱에
0 개
예제 삽입 작업이 하나만 포함되었습니다. 필요한만큼 추가하고 단순히 '동기화 된'방법인지 확인하십시오.
4 단계 - 활동에 SQLdataHelper을 사용
SQLdataHelper mDataHelper = SQLdataHelper.getInstance();
mDataHelper.insertTableA("Someone", 100);
은 [컨텐트 프로] (http://developer.android.com/reference/android/content/ContentProvider.html는) – Selvin
컨텐트 프로는 겉으로는 과잉이다 이 앱은 다른 앱과 공유 할 필요가 없으므로 나는 내 솔루션을 만들기 위해 다음과 같은 영감을 받았다. (나는 곧 솔루션의 해골을 게시 할 것이다) http://stackoverflow.com/questions/987072/using-application-context-everywhere –