Java Code Examples for android.content.Context#deleteDatabase()

The following examples show how to use android.content.Context#deleteDatabase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBTasksTest.java    From AntennaPodSP with MIT License 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    destFolder = getInstrumentation().getTargetContext().getExternalFilesDir(TEST_FOLDER);
    assertNotNull(destFolder);
    assertTrue(destFolder.exists());
    assertTrue(destFolder.canWrite());

    final Context context = getInstrumentation().getTargetContext();
    context.deleteDatabase(PodDBAdapter.DATABASE_NAME);
    // make sure database is created
    PodDBAdapter adapter = new PodDBAdapter(context);
    adapter.open();
    adapter.close();

    SharedPreferences.Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext().getApplicationContext()).edit();
    prefEdit.putString(UserPreferences.PREF_EPISODE_CACHE_SIZE, Integer.toString(EPISODE_CACHE_SIZE));
    prefEdit.commit();
}
 
Example 2
Source File: UniversalSearchContractTest.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
private SQLiteDatabase createTables(final boolean delete, final UniversalSearchContract.Table... tables) {
    SQLiteDatabase db = null;
    final String filenamePrefix = "test.";
    RenamingDelegatingContext targetContextWrapper = new
            RenamingDelegatingContext(
            new MockContext2(), // The context that most methods are
            //delegated to
            getContext(), // The context that file methods are delegated to
            filenamePrefix);
    final Context context = new IsolatedContext(super.getContext().getContentResolver(), targetContextWrapper);
    try {
        db = context.openOrCreateDatabase(DATABASE, 1, null);
        for (final UniversalSearchContract.Table table : tables) {
            table.onCreate(db);
            log("Table " + table + " onCreate successful");
        }
        return db;
    } finally {
        if (null != db && delete) {
            db.close();
            context.deleteDatabase(DATABASE);
        }
    }
}
 
Example 3
Source File: DatabaseManualUpgradeTest.java    From android-job with Apache License 2.0 6 votes vote down vote up
@Test
public void testDatabaseUpgrade1to2to3to4to5to6() {
    Context context = ApplicationProvider.getApplicationContext();
    context.deleteDatabase(DATABASE_NAME);

    JobOpenHelper1 openHelper = new JobOpenHelper1(context);
    createDatabase(openHelper, false);
    createJobs(openHelper);

    createDatabase(new JobOpenHelper2(context), true);
    createDatabase(new JobOpenHelper3(context), true);
    createDatabase(new JobOpenHelper4(context), true);
    createDatabase(new JobOpenHelper5(context), true);

    checkJob();
}
 
Example 4
Source File: DBWriterTest.java    From AntennaPodSP with MIT License 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
    super.setUp();
    final Context context = getInstrumentation().getTargetContext();
    context.deleteDatabase(PodDBAdapter.DATABASE_NAME);
    // make sure database is created
    PodDBAdapter adapter = new PodDBAdapter(context);
    adapter.open();
    adapter.close();
}
 
Example 5
Source File: Benchmark.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@Test
public void runBenchmark() {
    final int runs = 5;
    Statistics android = new Statistics();
    Statistics requery = new Statistics();
    for (int i = 0; i < runs; i++) {

        Context context = ApplicationProvider.getApplicationContext();
        String dbName = "testAndroid.db";
        context.deleteDatabase(dbName);
        platformSQLite = new PlatformSQLite(context, dbName);
        dbName = "testRequery.db";
        context.deleteDatabase(dbName);
        requerySQLite = new RequerySQLite(context, dbName);

        testAndroidSQLiteRead(android);
        testRequerySQLiteRead(requery);

        if (platformSQLite != null) {
            platformSQLite.close();
        }
        if (requerySQLite != null) {
            requerySQLite.close();
        }
    }
    Log.i(TAG, "Android: " + android.toString());
    Log.i(TAG, "requery: " + requery.toString());
}
 
Example 6
Source File: DatabaseDefinition.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
public void destroy(@NonNull Context context) {
    if (!isResetting) {
        isResetting = true;
        getTransactionManager().stopQueue();
        getHelper().closeDB();
        context.deleteDatabase(getDatabaseFileName());

        openHelper = null;
        isResetting = false;
    }
}
 
Example 7
Source File: Sensor.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void DeleteAndInitDb(Context context) {//KS
    Configuration dbConfiguration = new Configuration.Builder(context).create();
    try {
        ActiveAndroid.dispose();
        context.deleteDatabase("DexDrip.db");
        //ActiveAndroid.initialize(dbConfiguration);
        Log.d("wearSENSOR", "DeleteAndInitDb DexDrip.db deleted and initialized.");
    } catch (Exception e) {
        Log.e("wearSENSOR", "DeleteAndInitDb CATCH Error.");
    }
}
 
Example 8
Source File: MeasurementsDatabase.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public static void deleteDatabase(Context context) {
    Timber.d("Deleting corrupted database");
    synchronized (MeasurementsDatabase.class) {
        invalidateInstance();
        boolean deleted = context.deleteDatabase(DATABASE_FILE_NAME);
        Timber.w("Corrupted database deleted = %s", deleted);
    }
}
 
Example 9
Source File: DatabaseManualUpgradeTest.java    From android-job with Apache License 2.0 5 votes vote down vote up
@Test
public void testDatabaseUpgrade4to6() {
    Context context = ApplicationProvider.getApplicationContext();
    context.deleteDatabase(DATABASE_NAME);

    JobOpenHelper4 openHelper = new JobOpenHelper4(context);
    createDatabase(openHelper, false);
    createJobs(openHelper, true);

    checkJob();
}
 
Example 10
Source File: SQLiteOpenHelperTest.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
@Before
public void deleteDatabase() {
    Context ctx = InstrumentationRegistry.getTargetContext();
    SQLiteOpenHelper.getHelper(ctx).close();
    ctx.deleteDatabase(SQLiteOpenHelper.SQLITE_DATABASE_NAME);
}
 
Example 11
Source File: SQLiteLocationDAOTest.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
@Before
public void deleteDatabase() {
    Context ctx = InstrumentationRegistry.getTargetContext();
    ctx.deleteDatabase(SQLiteOpenHelper.SQLITE_DATABASE_NAME);
}
 
Example 12
Source File: ThemeChangedReceiver.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private void clearWidgetPreviewCache(Context context) {
    context.deleteDatabase(LauncherFiles.WIDGET_PREVIEWS_DB);
}
 
Example 13
Source File: DaoManager.java    From sqlbrite-dao with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes the complete database file
 */
public void delete(Context c) {
  c.deleteDatabase(getName());
}
 
Example 14
Source File: KeyValDatabase.java    From GodotSQL with Apache License 2.0 4 votes vote down vote up
public void purgeDatabase(Context context) {
	context.deleteDatabase(DATABASE_NAME);
}
 
Example 15
Source File: V2exDatabase.java    From v2ex with Apache License 2.0 4 votes vote down vote up
public static void deleteDatabase(Context context) {
    context.deleteDatabase(DATABASE_NAME);
}
 
Example 16
Source File: DataCleanUtil.java    From xmpp with Apache License 2.0 2 votes vote down vote up
/**
 * 按名字清除本应用数据库
 *
 * @param context
 * @param dbName
 */
public static void cleanDatabaseByName(Context context, String dbName) {
    context.deleteDatabase(dbName);
}
 
Example 17
Source File: Twitt4droidDatabaseHelper.java    From twitt4droid with Apache License 2.0 2 votes vote down vote up
/**
 * Destroys the twitt4droid database.
 * 
 * @param context the application context.
 */
public static void destroyDb(Context context) {
    context.deleteDatabase(NAME);
}
 
Example 18
Source File: DataCleanUtil.java    From NewFastFrame with Apache License 2.0 2 votes vote down vote up
/**
 * 按名字清除本应用数据库
 *
 * @param dbName
 */
public static void cleanDatabaseByName(Context context, String dbName) {
    context.deleteDatabase(dbName);
}
 
Example 19
Source File: DataClearManager.java    From Dota2Helper with Apache License 2.0 2 votes vote down vote up
/**
 * * 按名字清除本应用数据库 * *
 *
 * @param context
 * @param dbName
 */
public static void cleanDatabaseByName(Context context, String dbName) {
    context.deleteDatabase(dbName);
}
 
Example 20
Source File: RxFileTool.java    From RxTools-master with Apache License 2.0 2 votes vote down vote up
/**
 * 根据名称清除数据库
 * <p>/data/data/com.xxx.xxx/databases/dbName</p>
 *
 * @param dbName 数据库名称
 * @return {@code true}: 清除成功<br>{@code false}: 清除失败
 */
public static boolean cleanInternalDbByName(Context context, String dbName) {
    return context.deleteDatabase(dbName);
}