Search code examples
androidfileramtemporary

How to make a file get deleted after X time in Android?


There's the question. I've been looking for some solution about deleting a .pdf(for example) after a short time.

I'm not looking for the code, just for some info because I'm quite new into Android.

Is it possible to save the pdf into RAM and then free that RAM so the pdf gets deleted?

Is it possible to make that pdf temporary in some other way?

I'm so lost at the moment about this topic, so any info would be welcome.

Thanks in advance.


Solution

  • I think you should use a service to achieve this, first of all it will download the pdf and save id into a temporary folder, then with a Handler and its postDelayed(java.lang.Runnable, long) method, or a Timer and a TimerTask, you could delete this file.

    Links:

    1. http://developer.android.com/reference/java/util/TimerTask.html
    2. http://developer.android.com/reference/android/os/Handler.html