How to clear default realm database in android ? I tried following code but cannot resolve method deleteRealmFile.
Method 1 :
try {
Realm.deleteRealmFile(context);
//Realm file has been deleted.
} catch (Exception ex){
ex.printStackTrace();
//No Realm file to remove.
}
I tried to delete using configuration.
Method 2 :
try {
Realm.deleteRealm(realm.getConfiguration());
//Realm file has been deleted.
} catch (Exception ex){
ex.printStackTrace();
//No Realm file to remove.
}
but is gives the error:
java.lang.IllegalStateException: It's not allowed to delete the file associated with an open Realm. Remember to close() all the instances of the Realm before deleting its file.
try { Realm. deleteRealmFile(getActivity()); //Realm file has been deleted. } catch (Exception ex){ ex. printStackTrace(); //No Realm file to remove. }
You can find your realm file in the Device File Explorer tab at the bottom right of Android Studio. The location will be /data/data/com.
The Realm SDKs use Atlas Device Sync to synchronize app data between clients and MongoDB Atlas.
Realm is an object database that is simple to embed in your mobile app. Realm is a developer-friendly alternative to mobile databases such as SQLite and CoreData. Before we start, create an Android application.
Before Realm.deleteRealm(realm.getConfiguration());
just add realm.close()
like below and it works like a charm
try {
realm.close()
Realm.deleteRealm(realm.getConfiguration());
//Realm file has been deleted.
} catch (Exception ex){
ex.printStackTrace();
//No Realm file to remove.
}
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