I'm currently trying to scan the file system for mp3 files. I did an AsyncTask
that scans a directory and if finds a subfolder, it calls doInBackground() again for that subfolder and so on. However, this seems to crash the application. Is there any way to call doInBackground()
recursively?
@Override
protected List<File> doInBackground(String... params) {
if (isCancelled()) return foundFiles_;
publishProgress(String.valueOf(foundFiles_.size()));
File file = new File(params[0]);
String [] files = file.list();
for(String fileName : files)
{
File foundFile = new File(fileName);
if(foundFile.isDirectory())
{
doInBackground(fileName);
}
else
foundFiles_.add(foundFile);
}
return foundFiles_;
}