java - Android Memory -- Temporary Files in Cache or Put on Disk, Delete When Done -


i writing app records , plays audio using temporary file on device , longer-term storage on cloud, needs available on physical device when directly in use.

it allows user record , review recording, either delete or upload backend , delete phone. later, user downloads file backend server, listens it, , should deleted off phone.

these recordings may 10-15 minutes long, can large.

i made program work 2 different ways, i'm not sure 1 manages memory , cache. first calling temporary cache file following code:

    string filename = uuid.randomuuid().tostring().replaceall("-", "");     file tempfiledir = this.getcachedir();     file tempfile = file.createtempfile(filename, ".3gp", tempfiledir); 

this file used never directly deleted.

the other option saving non-cache file memory , deleting when no longer needed:

if (utils.isexternalstoragewritable()) {     string filename = getrandomfilename();    string outputfile = environment.getexternalstoragedirectory().getabsolutepath();    outputfile += "/" + filename + ".3gp";     //outputfile used in mediarecorder record sound file, etc.    //once file deleted:      file file = new file(outputfile);     boolean isdeletesuccessful = file.delete();     } 

is better second option don't run memory issues in cache?


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo