title: Clear Cache in Android Application programmatically
body: <p>what is the correct way to clear cache in android Application programmatically. I already using following code but its not look work for me</p>
  
  <pre><code>@Override
  protected void onDestroy() {
      // TODO Auto-generated method stub
      super.onDestroy();
      clearApplicationData();
  }
  
  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("EEEEEERRRRRRROOOOOOORRRR", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
              }
          }
      }
  }
  
  public static boolean deleteDir(File dir) {
      if (dir != null &amp;&amp; dir.isDirectory()) {
          String[] children = dir.list();
          for (int i = 0; i &lt; children.length; i++) {
              boolean success = deleteDir(new File(dir, children[i]));
              if (!success) {
                  return false;
              }
          }
      }
  
      return dir.delete();
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/g7lCU.png" alt="Image from my android phone"></p>