Android Question How to perform resource management while batch copying files?

Inman

Well-Known Member
Licensed User
Longtime User
In my app I have a For Next loop that is used to copy all files in a particular folder. Since the target location is a URI, I use the method given here to copy the files. And it works correctly too.

The problem arises when there are a lot of files to copy. Like there is a user who tried to copy about 3000 files in a folder. He reported that every time he tried, the loop copies a few files and then goes to stay in "not responding" mode. He then force stops it, tries again, copies a few more and then "not responding".

I am wondering if this has something to do with the app running out of resources. I have tried the same with like 10 to 50 files and it never had any issues. But apparently with 1000+ files it hangs.

So is there a right way to lock and release resources after copying each file?
 

Inman

Well-Known Member
Licensed User
Longtime User
Thanks Erel. I will make this change in the activity's code.

Besides activity, I also perform similar copy operation in a service as well using File.Copy2. Since there is no UI thread here, is it necessary to change this Copy2 to Copy2Async?
 
Upvote 0
Top