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