[Solved] Delete records from SQLite in Android [closed]


Since you are not going to keep any records offline after pushing to server.

you can just delete all the records of the table after the successful API call.

public void deleteAll(String tableName){

SQLiteDatabase db = this.getWritableDatabase();

db.execSQL("DELETE FROM "+tableName); 

db.close();

}

if you plan to keep records offline you can have a separate column like status to reflect various states of the record(It depends upon the requirement)

Value -> Meaning

A -> Added and not synced to server

S -> Synced to server

M -> Modified the synced record

DL -> Deleted locally

D -> completely deleted both in server and app.

you can use Update sql command for modifying status of existing column.

If you plan to delete some records based on Status value.Let’s D is completely useless.so we can go ahead like.

public void deleteMarked(String tableName){

SQLiteDatabase db = this.getWritableDatabase();

db.execSQL("DELETE FROM "+tableName+" where status="D"");

db.close();

}

3

solved Delete records from SQLite in Android [closed]