0
我需要在之前的應用程序中模擬設置 - >清除數據功能以關閉用戶帳戶。爲此,我使用下面的代碼;在關閉帳戶之前清除應用程序數據
private boolean clearCacheData() {
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if (appDir.exists()) {
String[] children = appDir.list();
boolean result = true;
for (String s : children) {
if (!s.equals("lib")) {
result &= deleteDir(new File(appDir, s));
Log.i("TAG",
"**************** File /data/data/APP_PACKAGE/"
+ s + " DELETED *******************");
}
}
return result;
}
return false;
}
private boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
}
當我這樣做時,我還打開我的歡迎頁面,以便爲用戶更改重新激活帳戶。如果用戶繼續重新激活我的應用程序崩潰並給出磁盤I/O錯誤Sq-lite
。但是,如果用戶殺死應用程序,然後重新打開它,一切都只是預期的工作。可能是什麼問題?
我忘了關閉什麼嗎?
看起來好像當你的代碼忙於刪除目錄並且用戶再次註冊時你試圖重新創建目錄。 我會建議同步數據的讀/寫到文件系統。 – Mobility