我正在尝试从内部存储中清除我的应用程序的所有数据,问题是它正在使用模拟器。我可以删除所有文件,将所有共享首选项设置为默认值并删除数据库,但是当我在重置应用程序后在手机上运行i(HTC EVO 3D)时,我从Web服务器收到的图像没有显示...可能发生的唯一方法是,如果我已经将它们放在我的数据库中......这真的很奇怪,因为我已经删除了数据库和所有其他文件。这是我正在使用的代码:
//Delete sqlite files :
boolean dbFile = deleteDatabase("stampii_sys_tpl.sqlite");
Log.e("","deleted : "+dbFile);
String cache = this.getCacheDir().toString();
Log.e("","dbPath : "+cache);
File ChFolder = new File(cache);
boolean cachee = deleteDirectory(ChFolder);
Log.e("","Database Folder Delete Success : "+cachee);
// Delete Databases Folder :
String dbPath = "/data/data/"+this.getPackageName()+"/databases/";
Log.e("","dbPath : "+dbPath);
File dbFolder = new File(dbPath);
boolean dbFold = deleteDirectory(dbFolder);
Log.e("","Database Folder Delete Success : "+dbFold);
// Delete Files Folder :
String name = this.getFilesDir().toString();
Log.e("","path : "+name);
File files = new File(name);
boolean filesFol = deleteDirectory(files);
Log.e("","filesFol : "+filesFol);
// Clear Shared Preferences :
editor.putBoolean("resetApp", false);
editor.putBoolean("isLoggedIn", false);
editor.putInt("storagePath", 0);
editor.putInt("lastUser", 0);
editor.putBoolean("getInfoFromJsonForColl", true);
editor.commit();
static public boolean deleteDirectory(File path) {
if( path.exists() ) {
File[] files = path.listFiles();
if (files == null) {
return true;
}
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
return( path.delete() );
}
所以我的问题是......我做错了什么,如果Android有可能以某种方式保留缓存中的应用程序数据库或类似的东西......即使原始文件被删除。
提前致谢!
答案 0 :(得分:1)
为什么不删除表中的数据,而不是删除数据库文件。在这种情况下,您无需复制粘贴或再次创建数据库。只需清除您不再需要的数据,这应该可以解决您的问题! :)