My Android App’s sqlite is synchronized with a back-end server database.
i want that when the database is deleted for some reason (e.g, app is uninstalled) to update my server that he should remove rows from its table.
i’m looking for some kind of a handler, but i can’t find anything like onDatabaseDelete().
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DBAdapter.DATABASE_NAME, null, DBAdapter.DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
i guess as a workaround i could do this when the app is uninstalled, but this is less “elegant”.
Can anyone please tell me if there’s a way of doing it in an elegant way (from a db handler and not when the app is uninstalled)?
EDIT:
Is it possible to put a handler on the app uninstall? is it possible to run a few actions before the app is uninstalled?
The application database file is located at /data/app_package/databases. When application is uninstalled all it’s private data is removed (/data/app_package). You can’t receive notification when the application is uninstalled or when it’s private data is deleted. A simple workaround will be every time the application starts to send keepAlive message to the server to indicate that it’s still alive. On the server side you’ll delete records for which you did’t receive keepAlive messages for more that some period ( it depends on your data ). You’ll come up with two problems –