Is there any way I can reset all application data? I mean, database, cache, application folder, etc. I want to do it when applications onDestroy()
is called. I am looking for a global solution - I don't know created tables in database, I know only package name.
Asked
Active
Viewed 376 times
0

Heisenberg
- 3,153
- 3
- 27
- 55
-
2[Clear Application's Data Programatically](http://stackoverflow.com/questions/6134103/clear-applications-data-programatically) – Vivart Nov 11 '13 at 08:41
-
http://www.rgagnon.com/javadetails/java-0483.html – diordna Nov 11 '13 at 08:45
-
Well, I know all of these, they are pretty much the same. But it doesn't workk perfectly. I was looking for something like universal android built-in method that does it – Heisenberg Nov 11 '13 at 08:51
-
I think global solution is, you know what you are creating in your app just delete those things, e.g. if you are creating sharedprefs, delete it using SharedPreferences.Editor.clear().commit(), you can delete database using context.deleteDatabase(DATABASE_NAME), etc – Vivart Nov 11 '13 at 09:07
1 Answers
0
Try this code.
public void clearApplicationData() {
File cache = getCacheDir();
File appDir = new File(cache.getParent());
if(appDir.exists()){
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++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
Courtesy hrupin. For more click here

Aju
- 4,597
- 7
- 35
- 58