Why does a singleton class survive?

I have a Singleton class that I use with one of the actions of my application.

When I exit the action, which returns me to the menu action and then opens the activity again, I find that when I try to access the single, it’s all the same. Was it really supposed to be destroyed with Activity?

I saw a question here: live singleton, when activity ends but could not fully follow what they mean.

When I press the return button on my device (or use the finish inside the operation itself), is activity active for future use? If so, then this will explain it.

+7
source share
1 answer

Was it really supposed to be destroyed with Activity?

Not.

When I press the return button on my device (or use the finish inside the operation itself), is activity active for future use?

Activity is not. There is a process. Singletones are part of the virtual machine and will live as long as this happens. Exiting the last action does not immediately terminate the process, so the singleton lives at least for a while.

Android will eventually stop this process to free up memory for other applications. How quickly this is done, it depends on what the user is doing, what applications are installed, moon phases, etc.

+12
source

All Articles