Amir
Amir

Reputation: 165

Change device Language within my app

I want to be able to change my phone settings within a button click inside my app. To be precise, I would like to change the phone's language. So far I created values/strings and values-iw/strings (hebrew strings) and within a button click I changed the configuration as follows:

    if (myLocale != null) {
        Locale.setDefault(myLocale);
        Configuration config = new Configuration();
        config.locale = myLocale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }

This code changes the locale (I'm not sure about the difference between locale and language) but it does not affect all my activities. Thus, I tried to change the phone's language settings right from my app but did not manage to. Does anyone have an idea how do I make this code affect all my activities? Or instead - how to change my phone language (reflection??)...


To make myself clear - I have Activity A which calls Activity B (I have many more activities all with
android:launchMode="singleInstance" in AndroidManifest). In activity B I changed locale language and returned to Activity A by the following lines:

    final Intent intent2 = new Intent(this, MainActivity.class);
    startActivity(intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
    finish();

The locale change does not affect Activity A (but affects all other activities, among them activity B). I assume the reason it does not affect Activity A is that activity A is still in the stack. I didn't manage to affect Activity A when changing locale. Does anyone have an idea how to affect also Activity A?

Upvotes: 2

Views: 750

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006819

I want to be able to change my phone settings within a button click inside my app. To be precise, I would like to change the phone's language.

That is not possible, sorry.

within a button click I changed the configuration as follows

At most, that will affect your app, not the "phone".

Does anyone have an idea how do I make this code affect all my activities?

Run that same code in each activity, such as from onResume().

Upvotes: 1

Related Questions