Clear Firebase Persistence After Logout
Solution 1:
Unfortunately there's no supported way to clear the persistence cache. You could try to manually delete the SQLite database used by Firebase Database (should be under /databases/
in your app's data folder), but you'd need to do it before initializing Firebase Database, so you'd have to force the app to restart after signing somebody out or similar.
Regarding knowing if there's "data waiting to sync", assuming you're talking about writes, the only way is to attach CompletionListeners to every write operation you do, and wait for them to complete.
Both of these are things we'd like to improve in future versions of the Firebase Database SDK.
Solution 2:
clearPersistence()
was launched in v6.2.0.
via
Solution 3:
if (Build.VERSION_CODES.KITKAT <= Build.VERSION.SDK_INT) {
((ActivityManager) getContext().getSystemService(ACTIVITY_SERVICE))
.clearApplicationUserData();
}
Solution 4:
Oh dear what a terrible hack this solution is, I apologise in advance...
This works tho, to clear the local cache:
disable persistence
take a full copy of the new node, e.g. for user 2
e.g. var copyData = await (await ref.once()).value;
enable persistence
replace the new node, e.g. user 2, with the copyData
In theory only data which has been changed will be written, which should mean no changes to the realtime database. Meanwhile the local cache is replaced with the data from the server.
I got this approach to work for my needs. It's the basis of a solution, which would be different depending on every use case.
Good luck!
Post a Comment for "Clear Firebase Persistence After Logout"