How to Delete SQLite Database from Android Programmatically

How To Drop Android Sqlite Database Programmatically

Finally this is worked for me

First drop and create the database

  public void resetDatabase() {
SQLiteDatabase database = getWritableDatabase();
database.execSQL("DROP TABLE IF EXISTS " + Constants.CUSTOMER_TABLE);
database.execSQL("DROP TABLE IF EXISTS " + Constants.TRANSACTION_TABLE);
database.execSQL("DROP TABLE IF EXISTS " + Constants.RETAILER_TABLE);
database.execSQL(CREATE_CUSTOMER_TABLE);
database.execSQL(CREATE_TRANSACTION_TABLE);
database.execSQL(CREATE_RETAILER_TABLE);
database.close();
}

And then restart the app borrowed from this question how to programmatically "restart" android app?

public static void resetApp() {
sDatabase.resetDatabase();
preferenceEditor.clear();
preferenceEditor.commit();
Intent mStartActivity = new Intent(sContext, MainActivity.class);
int mPendingIntentId = 123456;
PendingIntent mPendingIntent = PendingIntent.getActivity(sContext, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager)sContext.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
System.exit(0);

}

delete database android sqlite

Write method in DatabaseHelper class where you have extended SQLiteOpenHelper class

/**
* Delete database
*/
public static void deleteDatabase(Context mContext) {
mContext.deleteDatabase(DATABASE_NAME);
}

then you can call directly like DatabaseHelper.deleteDatabase(mContext);

Thank you.

How to delete sqlite database of my application in android mobile manually

u can delete database manually by clear Data.

settings\applications\manage Applications\'select your application'\clear data.

How to delete all SQLite data from android studio?

This might work.

db.delete("TABLE_NAME", null, null);

Deleting or updating an entry in an SQLite database in Android

 public boolean UpdateData(String ID, String First, String Last, String  MAKE, String MODEL, String Cost) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();

cv.put(CUSTOMER_FIRST_NAME, First);
cv.put(CUSTOMER_LAST_NAME, Last);
cv.put(CAR_MAKE, MAKE);
cv.put(CAR_MODEL, MODEL);
cv.put(COST, Cost);
db.update(Table_name, cv, "ID = ?", new String[]{ID});
return true;
}

public Integer deleteData(String ID) {
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(Table_name, "ID =?", new String[]{ID});
}

This is what I used to complete a similar project



Related Topics



Leave a reply



Submit