title: Cache not getting cleared of Android Application programmatically?
body: <p>In my app because I use Bitmap factory to get bitmap image object from http url lot of data is getting cached. So i wrote following code to clear cache data everytime application loads. Its similar to what we do manually by clicking Clear Cache button in Setting -> Apps -> YOUR_APP.</p>
  
  <p>However following code i wrote is not working. Cache size is as it is. </p>
  
  <pre><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") &amp;&amp; !s.equals("shared_prefs")) {
                      deleteDir(new File(appDir, s));
                  }
              }
          }
      }
  
      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>I also added following permission in AndroidManifest.xml of my application:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CLEAR_APP_CACHE" /&gt;
  </code></pre>
  
  <p>Please help. And how we use Bitmap factory in efficient way to reduce performance and improve efficiency.</p>