1
我正在使用下面的代码清除android应用程序中的数据,但它并未清除所有数据。使用此代码后,当我看到应用程序信息时,它显示30kb的数据。我也看到很多教程在stackoverflow,但我无法清除我的应用程序的所有数据。如何以编程方式清除Android应用程序中的数据
public void clearApplicationData() {
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if(appDir.exists()){
//Log.i("TAG", "check the delete data==" +" DELETED");
String[] children = appDir.list();
for(String s : children){
if(!s.equals("lib")){
deleteDir(new File(appDir, s));
//Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s +" DELETED *******************");
}
}
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
Log.i("TAG", "check the delete data==" + children[i] +" DELETED count="+ i+" length="+children.length);
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
看看这个http://android-sample-code.blogspot.com/2012/01/how-to-clear-cache-data-in-android.html –
可能重复的[如何清除缓存Android] (http://stackoverflow.com/questions/6898090/how-to-clear-cache-android) – Szymon
我也尝试这两个教程,但它不清除应用程序中的所有数据。因为当我打开应用程序信息其显示36.00 kb的数据。 – jiten