Internal Cache Files
.
Internal cache files
Each app has a special and private cache directory to store temporary files. Android
may delete these files when the device is low on internal storage space, so it’s not
safe to store anything other than temporary files in this space. There’s also no
guarantee that Android will delete these files for you, so you must maintain this
directory yourself.
To write to the internal cache directory, use
createTempFile
as shown in the
following example:
File.createTempFile(filename,
null
, context.cacheDir)
A good use case for temporary files is when you’re uploading images to a server. You
may not need the image persisted on the device, but you still need to upload
some
file. In this case, a temporary file works well. You’d store the image in this temp file,
upload it, and then delete the file upon completion.
Now that you have utilized the important features of internal storage, it’s time to
look at how to store files on
Do'stlaringiz bilan baham: |