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
Cannot Resolve Symbol 'Theme' in Styles.Xml (Android Studio)
Accessing UI Thread Handler from a Service
Detecting Which Selected Item (In a Listview) Spawned the Contextmenu (Android)
Android: Crop an Image After Taking It with Camera with a Fixed Aspect Ratio
How to Know That My Webview Is Loaded 100%
How to Align Title at Center of Actionbar in Default Theme(Theme.Holo.Light)
Android Mask Bitmap on Canvas Gen a Black Space
No Good Example About Recyclerview and Staggeredgridlayoutmanager in Android Docs
How to Set a Viewpager Inside a Fragment
Listen Outgoing Sms or Sent Box in Android
Change the Font of Tab Text in Android Design Support Tablayout
Android Studio:Unmappable Character for Encoding Utf-8
Retrieve Google Access Token After Authenticated Using Firebase Authentication
Android Split Action Bar with Action Items on the Top and Bottom
How to Implement the Material-Design Elevation for Pre-Lollipop