android - How to recall onCreate( ) when onBackPressed( ) and go to previous activity? -
myapp testing multi language change. http://www.androhub.com/android-building-multi-language-supported-app/ after choose radio button, changes language in current activity. when go previous activity, doesn't change language. so, want recall oncreate when click button. or how refresh current activity?
oncreate ()
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main3); txt = (textview) findviewbyid(r.id.txt); radiogroup = (radiogroup) findviewbyid(r.id.radiogroup); radioeng = (radiobutton) findviewbyid(r.id.eng); radiohi = (radiobutton) findviewbyid(r.id.hi); // initialization pref = getsharedpreferences("mypref", activity.mode_private); editor = pref.edit(); radiogroup.setoncheckedchangelistener(new radiogroup.oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup radiogroup, @idres int i) { string lang = "en"; // default language switch (i) { case r.id.eng: lang = "en"; break; case r.id.hi: lang = "hi"; break; default: break; } changelocale(lang); // change locale on selection basis } }); loadlocale(); }
changelocale
private void changelocale(string lang) { if (lang.equalsignorecase("")) return; locale mylocale = new locale(lang); // set selected locale savelocale(lang); // save selected locale locale.setdefault(mylocale); // set new locale default configuration config = new configuration(); // configuration config.locale = mylocale; // set config locale selected locale getbasecontext().getresources().updateconfiguration(config, getbasecontext().getresources().getdisplaymetrics()); // update config }
savelocale & loadlocale
private void savelocale(string lang) { editor.putstring("save", lang); editor.commit(); if (lang.equals("en")) { radioeng.setchecked(true); } else { radiohi.setchecked(true); } } private void loadlocale() { string lang = pref.getstring("save", ""); if (lang.equals("")) { radioeng.setchecked(true); } else { changelocale(lang); } }
give resultcode when current activity, or save configuration, check configuration on activity resume language change
Comments
Post a Comment