title: How to clear cache Android
body: <p>I need to find a way how to clear the data which my application stores in cache.Basically I am using Fedor's ( <a href="https://stackoverflow.com/questions/541966/android-how-do-i-do-a-lazy-load-of-images-in-listview/3068012#3068012">Lazy load of images in ListView</a> ) lazy list implementation and I want to clear the cache automatically when I have for example 100 images loaded.Any ideas how to do that?</p>
  
  <p><strong>EDIT:</strong>
  Code :</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      list=(ListView)findViewById(R.id.list);
      adapter=new LazyAdapter(this, mStrings);
      list.setAdapter(adapter);
  
      deleteCache(this);
      adapter.notifyDataSetChanged();
  
  
  }
  
  public static void deleteCache(Context context) {
      try {
          File dir = context.getCacheDir();
          if (dir != null &amp;&amp; dir.isDirectory()) {
              deleteDir(dir);
          }
      } catch (Exception e) {}
  }
  
  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>