Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does static variable retains value even when android application is closed

I am developing an android application using bluetooth. When I launch my application for first time, my application works well, but when I exit the application and run it once again I get problems with bluetooth connectivity.

I am not able to establish connection with another device.I am using few critical static variables. My doubt is does these static variables retains the value even when application is exited.

Also i notice that my application is still running i mean its not stopped. Should we stop the application explicitly when we exit? If so ,how to do that. I am simply using finish when i exit the application.

like image 522
androidGuy Avatar asked Jun 12 '26 10:06

androidGuy


2 Answers

yaa it will retain value. because application once started does not get killed immediately. but you can not rely on this, because some time android os may kill long inactive processes to release memory. in this case you can loose your data.

like image 67
Sunil Pandey Avatar answered Jun 14 '26 21:06

Sunil Pandey


yes, static variable will be still in its memory. You can check upon your exit of app, clear out all the static fields declared

like image 35
mehul9595 Avatar answered Jun 14 '26 20:06

mehul9595



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!