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