I'm trying to copy all the image files on an SD card (connected to a rooted Android device running 4.0.4) to a Hard Drive connected to the same device. I'm new to Android programming so forgive me if the question's answer is obvious.
I use the following method, which is called from the onHandleIntent(Intent intent)
of a service, to to the copying:
private void copyImages(File sourceDirectory, File destinationDirectory) throws IOException {
int count = 0;
IOFileFilter imageFilter = new ImageFilter();
IOFileFilter visibleDirectoryFilter = new VisibleDirectoryFilter();
long startTime = System.nanoTime();
if (sourceDirectory.exists() && destinationDirectory.exists()) {
Collection<File> fileList = FileUtils.listFiles(sourceDirectory, imageFilter, visibleDirectoryFilter);
for (File image : fileList) {
FileUtils.copyFileToDirectory(image, destinationDirectory);
count++;
}
}
long totalTime = System.nanoTime() - startTime;
Toast.makeText(this, count + " files copied in " + (totalTime) + " nanos.", Toast.LENGTH_LONG).show();
}
However, when I run this, after 36 images are copied, I start continuously getting GC_CONCURRENT freed aK, b% free cK/dK, paused ems+fms
where a
, b
, c
, d
, e
and f
are different numbers. I get this non-stop for a long time (as long as I've waited) without any other images being copied.
I understand (I think I do anyway) that this is because the heap is full and Dalvik is trying to free up memory. But, I'm not sure how I can stop this from happening, the program should be able to copy many more (possibly thousands) images. Perhaps the apache commons FileUtils class is too heavy for Android in which case is there another Android-friendly library for neat file handling or must I write my own simple one? Or maybe I'm going wrong elsewhere.
Any help is much appreciated.
Thanks in advance.