I am working on I18N application which works for 6 countries, In have a requirement like, when the user changes the language from the settings, the application should be restart itself and display the app in changed language. for that I am storing the language value in shared preference and comparing with the current language value. if the value is not same I need to re-launch the application. For this I am using below code:
if (currentLanguage == null) {
Util.saveStringInSP(_activity, "LANGUAGE", languageValue);
}
else if (currentLanguage.equalsIgnoreCase(languageValue)) {
String currentLanguage = Util.getStringFromSP(_activity, "LANGUAGE");
}
else {
try {
android.os.Process.killProcess(android.os.Process.myPid());
}
catch(Exception e) { }
Intent i = new Intent();
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.pfizer.stablemate");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}
Please provide me a piece of code to relaunch the Android application programmatically.
Try :
Intent intent = getBaseContext().getPackageManager().getLaunchIntentForPackage(
getBaseContext().getPackageName() );
intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With