hope your doing fine, i have a problem with my sqliteDatabase, i am Holding my Database in a Service always running in background, and i get it like this :
public static SQLiteDatabase getPostsDatabase(){
if(PostsDatabase == null){
if(getAnAvailableContext() == null){ return null; }
PostsDbHelper = new PostsDBHelper(getAnAvailableContext());
PostsDatabase = PostsDbHelper.getWritableDatabase();
}
return PostsDatabase;
}
public static Context getAnAvailableContext(){
if(MainActivity.mainActivityInstance != null){
return MainActivity.mainActivityInstance;
}else if(getInstance() != null){
return getInstance();
}else{
return LMApplication.getInstance().getApplicationContext();
}
}
it works fine for first timer, but when the applications is restored from saved instance , and context instances change , my data on the database has changed and are wrong, my question is Is the Context Change really the Problem ? and if its so , how can i have a presistent context ? i tried to use application context for creating it but no improvement !
Aucun commentaire:
Enregistrer un commentaire