I am using a static variable in an activity in android (it is not the main activity). But when I go to the main activity and I press the back button, the static value remains the same. The back button does not kill the main process. Why?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using the back button destroys the activity, not the application. All activities are part of an application that is running in a Dalvik VM. The application is still there, running (even if all activities have been destroyed), until the system decides that it needs resources and kills the process.
As such, your static member will remain in memory as long as the process/app is running.
If you try running some memory-intensive application or closing the running application with some task manager, you may see the static value reset.