java - i have a class like this. FileCache.class. this method is used to create a dir in SDCard. it work well -


i have class this.... want know when inherit clear method use in mainactivity.class. delete file cache, right? ( if class there wrong please fill me) , how can use method clear in mainactivity?

public class filecache {

private file cachedir;  public filecache(context context){     //find dir save cached images     if (android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted))         cachedir=new file(android.os.environment.getexternalstoragedirectory(),"lao su kun fung");     else         cachedir=context.getcachedir();     if(!cachedir.exists())         cachedir.mkdirs(); }  public file getfile(string url){     .     string filename=string.valueof(url.hashcode());     file f = new file(cachedir, filename);     return f;  }  public void clear(){     file[] files=cachedir.listfiles();     if(files==null)         return;     for(file f:files)         f.delete(); } 

}

public class mainactivity extends activity{  filecache filecache; public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);               filecache=new filecache(); filecache.clear(); or  new filecache().clear(); try set static method of clear function   this... public static void clear() { }   , easly access in activity classname.methodname();    thank you.. 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -