I've deleted the room database but still, I can see the previous rows in my database inspector unless I kill the app manually and reopen it. The scenario is logging out and reopen the login activity. The code snippet:
class MyAppCompatActivity:AppCompatActivity(){
//...
private fun logOut() {
MyAppDatabase.getInstance(context).clearAllTables()
MyAppDatabase.getInstance(context).close()
deleteDatabase(MyAppDatabase.DATABASE_NAME)
MyFileUtil.deleteDir(cacheDir)
MyFileUtil.deleteDir(filesDir)
}
}
object MyFileUtil{
fun deleteDir(dir: File?): Boolean {
return if (dir != null && dir.isDirectory) {
val children = dir.list()
for (i in children.indices) {
val success = deleteDir(File(dir, children[i]))
if (!success) {
return false
}
}
dir.delete()
} else if (dir != null && dir.isFile) {
dir.delete()
} else {
false
}
}
}
Does anyone know how to clean my database and quickly reopen my activity again by doing an act like kill the app programmatically?