Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android finish() method doesn't clear app from memory

I have an activity and I call the finish() method and the activity is not cleared from memory.

After calling finish() , I see that the method onDestroy() is executed successfully (and I clear all my variables and stuff in there).

Should it be cleared from memory or its how android works? As I understand the LifeCycle of the Activity is finished.

And if it keeps the app in memory so it runs faster the 2nd time the user uses it, what kind of objects can I leave in memory to reuse? If I understand correctly, I am suppose to clear everything on onDestroy.

like image 853
Daniel Benedykt Avatar asked Dec 29 '09 22:12

Daniel Benedykt


3 Answers

Android keeps processes around in case the user wants to restart the app, this makes the startup phase faster. The process will not be doing anything and if memory needs to be reclaimed, the process will be killed. Don't worry about it :)

like image 144
Romain Guy Avatar answered Oct 23 '22 06:10

Romain Guy


Best way is firstly use finish() and after that use System.exit(0) to clear static variables. It will give you some free space.

A lot of applications leave working processes and variables what makes me angry. After 30 minutes of using memory is full and i have to run Task Manager - Lvl 2 clear memory

Its not true that is cousing problems i've tried it for over 3 years in my apps. Never get crashed or restart after using Exit()

like image 31
Tefel Avatar answered Oct 23 '22 07:10

Tefel


Try using

System.exit(0);

like image 12
Zahid Avatar answered Oct 23 '22 06:10

Zahid