I am having an issue with StrictMode i have the following AsyncTask
class pruneDiskCacheTask extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... params) {
pruneRecursive(DiskCache);
return null;
}
void pruneRecursive(File fileOrDirectory){
if (fileOrDirectory.isDirectory()) {
for (File child : fileOrDirectory.listFiles()) {
pruneRecursive(child);
}
}else {
if(checkForPruningAsync(fileOrDirectory)){
fileOrDirectory.delete();
}
}
}
public boolean checkForPruningAsync(File file){
String fileName = file.getName();
String type = fileName.substring(fileName.lastIndexOf(".")+1);
Date lastModified = new Date(file.lastModified());
if(type.equals("json")){
Date cacheLifetime = new Date(new Date().getTime() - keepJsonFor);
if(lastModified.before(cacheLifetime)){
return true;
}
}else if(type.equals("txt")) {
Date cacheLifetime = new Date(new Date().getTime() - keepTxtFor);
if(lastModified.before(cacheLifetime)){
return true;
}
}else{
Date cacheLifetime = new Date(new Date().getTime() - keepImagesFor);
if(lastModified.before(cacheLifetime)){
return true;
}
}
return false;
}
}
It is throwing a StrictMode error (does not seem to be crashing the program but i don't like it popping up)
android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk
My understanding is that if you put something into an Async Task it meets the requirements of StrictMode. But in this case i seem to be wrong. can someone tell me what I am doing wrong please?
EDIT
Here is how i call the Async Task as requested
public void pruneDiskCache(){
synchronized (mDiskCacheLock) {
// Wait while disk cache is started from background thread
while (mDiskCacheStarting) {
try {
mDiskCacheLock.wait();
} catch (InterruptedException e) {
}
}
if(DiskCache.exists()) {
new pruneDiskCacheTask().execute();
}
}
}
This is called from within my Cache Class which is created as so
mActivity = this;
cacheHandeler = new Cache(mActivity);
from within my main thread.