Whenever a user logs in, I am trying to check if the user is same as previously logged in user or not.If the user is different I am trying to delete all the database instance and then create the instance for the newly logged in user.If the user is same then user data should be deleted
How to delete database instance ? Tried
Realm.getDefaultConfiguration()?.let {
Realm.getDefaultInstance().close()
Realm.deleteRealm(it)
}
But got following exception
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: /data/data/com.mypackage.name/files/filename.realm
How to close all the instances and delete them?