diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java b/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java index ccafcc55..838b4348 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/Poche.java @@ -207,7 +207,7 @@ public class Poche extends Activity implements FeedUpdaterInterface { if (pref.getInt("update_checker", 0) < 9) { // Wipe Database, because we now save HTML content instead of plain text ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); - database = helper.getReadableDatabase(); + getDatabase(); helper.truncateTables(database); showToast("Update: Wiped Database. Please synchronize."); } @@ -229,6 +229,13 @@ public class Poche extends Activity implements FeedUpdaterInterface { apiToken = settings.getString("APIToken", ""); } + private void getDatabase() { + if (database == null) { + ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(this); + database = helper.getReadableDatabase(); + } + } + @Override protected void onResume() { super.onResume(); @@ -258,7 +265,7 @@ public class Poche extends Activity implements FeedUpdaterInterface { runOnUiThread(new Runnable() { public void run() { ArticlesSQLiteOpenHelper helper = new ArticlesSQLiteOpenHelper(getApplicationContext()); - database = helper.getReadableDatabase(); + getDatabase(); int news = database.query(ARTICLE_TABLE, null, ARCHIVE + "=0", null, null, null, null).getCount(); btnGetPost.setText(String.format(getString(R.string.btnGetPost), news)); } @@ -301,4 +308,4 @@ public class Poche extends Activity implements FeedUpdaterInterface { updateUnread(); findViewById(R.id.progressBar1).setVisibility(View.GONE); } -} \ No newline at end of file +}