C
C
Chvalov2015-10-08 08:50:00
Java
Chvalov, 2015-10-08 08:50:00

Clearing the cache when exiting the program and a complete stop, how to implement?

I would like to clear the cache when exiting the program and, if possible, completely unload it from RAM.
I found a couple of code sketches, but I don’t know which one will be effective and more correct:
Here 1 option , Here 3 options
Regarding unloading from RAM, as I understand it, even when exiting the program, it weighs in RAM and in the list of recently launched applications, if it is one there to remove, then the RAM increases.
It feels like I didn’t leave the program, but turned it off, although I use this one: finish();
And also tell me what is the difference between finish(); and System.exit(); - what do the int values ​​in System.exit(?);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Varakosov, 2015-10-08
@Chvalov

1. The application cache is very easy to clean. You need to call getCacheDir() on the context and then delete the returned folder. Still need to add permission
2. Regarding the exit from the application. You do not understand a little how the system works with memory.
For now, it is recommended to use finish(). And the RAM will be cleaned by the garbage collector, if necessary. In AsyncTask and services, use weak references, otherwise the memory they occupy is not guaranteed to be cleared.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question