• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does jvm cleaned if application force closes

 
Abdul Aatif
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an created an application , In the first screen user will select language from spinner,(in spinner, onItemselectedlistener i have written a code to store the selected language in static varible )


// selecting language

spn_lanSel.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {

if (arg2 == 1) {
LANGUAGE = "en";
} else if (arg2 == 2) {
LANGUAGE = "ta";
}

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {

}
});




, now in the other screens i am using that static varible

// in other screens(activity)

if (LanguageSel.LANGUAGE.equals("en")) {

// making all text views as enhlish
}else{
// making all text views as other language
}

the problem is , if application is closing unexpectedly(i have written bluetooth code in emulator) , i am viewing the screen in other language(why it is happening ? Does jvm cleaned if application force closes ) i have checked the content in LanguageSel.LANGUAGE(static varible , it is empty ie.. " ")



thanks in advance
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, every time the application closes, you should expect the JVM to have exited and the the class to have been unloaded. If the application closes normally than this isn't always true, but on a crash, or a prolonged absence it will be. If you want to make sure the language persists you should use a SharedPreference to store the value: not a static variable. Then, when you need it, load it from the SharedPreference and when you let the user change it, write it to the SharedPreference.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this on the Android Developers network.
 
Abdul Aatif
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Thank you very much Sir.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic