My app uses the SyncAdapter
pattern, holding user credentials using the AccountManager
and a ContentProvider
to store data in a db.
When the account
gets removed I can remove the db using the approach explained in this question. The db gets removed by doing:
boolean deleted = mContext.deleteDatabase(DatabaseHelper.DATABASE_NAME);
This works fine but when I do the login again everything is still there. It feels like the ContentProvider
doesn't know that the db has been removed.
In this answer, inazaruk says:
You need to make sure you've killed the process that hosts ContentProvider that uses that specific database file. And only than delete it.
Killing the process to clear a db doesn't feel right.
Is there a better thing to do?
If I'd had to do that I would try it the following way:
add some Uri
that when you insert or delete using that Uri
triggers database deletion inside your ContentProvider
. When deleting also clear all references to the SQLiteDatabase
since it is possible that you can still access the old database file through that (If you delete a file in Linux and you have that file open you can still use it - it's just no longer accessible via the path).
By putting the deletion inside the ContentProvider
you should be able to close the database connection and track the deletion state in a way that you know that you need to recreate the database file.
ContentProviders
don't quit unless you kill your app so you probably have the same instance running and probably references to the old file as mentioned above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With