Reputation: 17753
is there any efficient way how to have splash screen, which will be used for selecting language for an application? Now I am using SetLocale method, but it needs restarting of whole application, is there any way how to change language at a runtime?
Thx
Upvotes: 0
Views: 1116
Reputation: 3263
You may not restart the app, but just "reload" the activity (or, in your case, entering the new one, after setting the Locale), calling the method below, after you selected the language in your splash screen.
public static void reload(Activity activity) {
Intent intent = activity.getIntent();
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
activity.finish();
activity.overridePendingTransition(0, 0);
activity.startActivity(intent);
activity.overridePendingTransition(0, 0);
}
The two overridePendingTransition(0, 0)
are there because I found that are both necessary if I want to cut out the animation for both the exit and the entering of the "recycled"activity. Also, the behavior was different between ICS and JB, so I also left the redundant setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
.
(I use the method above also for applying "on the fly" a theme switch between dark and light holo).
EDIT:
Anyway, to change locale I use something like:
locale = new Locale(param0, param1);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
including
android:configChanges="locale|orientation|screenSize|keyboard|keyboardHidden"
into the Manifest, under the activity that uses this method.
If you want I can post (or link to) the source to the complete method I use to initialize the Locale in every onCreate(...)
methods of my App. It is used to force the locale to the one stored into the preferences (falls back to the default one).
Upvotes: 1