Source:
private void checkIfDatabaseUpdated(){ long busDBLastUpdate = sp.getLong("busDBTimeUpdated", -1); boolean busDBUpdate = false; if (busDBLastUpdate != -1){ long day = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - busDBLastUpdate); LogHelper.d("INIT", "Bus DB Last Update: " + day); if (day > 30) busDBUpdate = true; } int dbver = sp.getInt("busDBVerCheck", 0); LogHelper.d("DB UPGRADE", "Current DB Version: " + dbver); switch (dbver) { case 0: case 1: LogHelper.i("DB UPGRADE", "Upgrading to V2 API DB"); busDBUpdate = true; sp.edit().putInt("busDBVerCheck", 2).apply(); break; case 2: LogHelper.i("DB UPGRADE", "Upgrading to DB with Bus Services"); busDBUpdate = true; sp.edit().putInt("busDBVerCheck", 3).apply(); break; } if (!sp.getBoolean("busDBLoaded", false) || busDBUpdate){ if (!ConnectivityHelper.hasInternetConnection(getApplicationContext())) { networkUnavailable(getString(R.string.database_name_bus)); } else { LogHelper.d("INIT", "Initializing Bus Stop Database"); ProgressDialog dialog = new ProgressDialog(this); dialog.setTitle(getString(R.string.database_name_bus)); dialog.setMessage(getString(R.string.dialog_message_retrieve_data_from_server)); dialog.setCancelable(false); dialog.setIndeterminate(true); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); BusStopsDB db = new BusStopsDB(this); db.dropAndRebuildDB(); sp.edit().putBoolean("busDBLoaded", false).apply(); dialog.show(); new GetAllBusStops(dialog, db, this, sp).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 0); } } else { if (sp.getLong("busDBTimeUpdated", -1) == -1){ sp.edit().putLong("busDBTimeUpdated", System.currentTimeMillis()).apply(); } } }

Target:
private void checkIfDatabaseUpdated(){ long busDBLastUpdate = sp.getLong("busDBTimeUpdated", -1); boolean busDBUpdate = false; if (busDBLastUpdate != -1){ long day = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - busDBLastUpdate); LogHelper.d("INIT", "Bus DB Last Update: " + day); if (day > 30) busDBUpdate = true; } final String DBTAG = "DB UPGRADE"; int dbver = sp.getInt("busDBVerCheck", 0); LogHelper.d(DBTAG, "Current DB Version: " + dbver); switch (dbver) { case 0: case 1: LogHelper.i(DBTAG, "Upgrading to V2 API DB"); busDBUpdate = true; sp.edit().putInt("busDBVerCheck", 2).apply(); break; case 2: LogHelper.i(DBTAG, "Upgrading to DB with Bus Services"); busDBUpdate = true; sp.edit().putInt("busDBVerCheck", 3).apply(); break; } if (!sp.getBoolean("busDBLoaded", false) || busDBUpdate){ if (!ConnectivityHelper.hasInternetConnection(getApplicationContext())) { networkUnavailable(getString(R.string.database_name_bus)); } else { LogHelper.d("INIT", "Initializing Bus Stop Database"); ProgressDialog dialog = new ProgressDialog(this); dialog.setTitle(getString(R.string.database_name_bus)); dialog.setMessage(getString(R.string.dialog_message_retrieve_data_from_server)); dialog.setCancelable(false); dialog.setIndeterminate(true); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); BusStopsDB db = new BusStopsDB(this); db.dropAndRebuildDB(); sp.edit().putBoolean("busDBLoaded", false).apply(); dialog.show(); new GetAllBusStops(dialog, db, this, sp).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, 0); } } else { if (sp.getLong("busDBTimeUpdated", -1) == -1){ sp.edit().putLong("busDBTimeUpdated", System.currentTimeMillis()).apply(); } } }