aspose file tools*
The moose likes Android and the fly likes Does jvm cleaned if application force closes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Does jvm cleaned if application force closes" Watch "Does jvm cleaned if application force closes" New topic
Author

Does jvm cleaned if application force closes

Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23
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

Joined: Jan 28, 2003
Posts: 4181
    
  21

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
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

See this on the Android Developers network.
Abdul Aatif
Greenhorn

Joined: Feb 08, 2012
Posts: 23



Thank you very much Sir.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Does jvm cleaned if application force closes