0

I have a code to clear application data, but after restarting the application. All data comes back.

public static void ClearApplicationData() {
    File cacheDir = GetCurrentApplication().getCacheDir();
    File appDir = new File(cacheDir.getParent());
    if (appDir.exists()) {
        String[] children = appDir.list();
        if (children == null)
            return;
        for (String s : children) {
            if (!s.equalsIgnoreCase("lib"))
            {
                File dirToDelete = new File(appDir, s);
                                    //delete directory code

            }
        }
    }
}

So after executing the above code, I checked the data dir of application and it only had lib directory left. But as I run application again, all directories back as they were before. But if I use Manage Application > App Info > Clear Data, all works good. Whats the difference ?

xmen
  • 1,947
  • 2
  • 25
  • 47

1 Answers1

0

How are you deleting the directory? File class doesn't delete a directory if it isn't empty. You should implement a recursive delete method or use Apache Commons IO instead.

Here is a useful link: deleting folder from java

Community
  • 1
  • 1
DanielGL
  • 26
  • 4
  • Yes I'm aware of that, please read question till end. As I said, it does delete all required directories. But they comes back after starting app again. – xmen Sep 22 '13 at 10:47
  • Sorry about that. Have you checked if files into directories also come back? Or it only comes back the directory structure? Maybe Android needs some directories to be created at first lauch. – DanielGL Sep 22 '13 at 11:16
  • Shared preference value stays same as last set, not default, Even all files are deleted. Yes files inside directories also comes back with old values. Only Clear Data from Settings, works perfectly. – xmen Sep 22 '13 at 13:33