2

In my multilingual application I want to fresh restart my application from the launcher activity. But I am unable to do so. I have changed the application manifest by removing the

locale

from the

android:configChanges="orientation|keyboardHidden"

but its not working for me. Manifest:

 <application
        android:name=".Global.MyApp"
        android:allowBackup="true"
        android:icon="@drawable/login_meter"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
.....
.....
 <activity
            android:name=".SplashActivity"
            android:configChanges="orientation|keyboardHidden"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme"
            >
            <intent-filter>
                ....

            </intent-filter>
        </activity>

....
....

</application>
Mehvish Ali
  • 732
  • 2
  • 10
  • 34
  • http://stackoverflow.com/questions/8049207/how-to-refresh-activity-after-changing-language-locale-inside-application – Rajakumar Dec 21 '16 at 11:13

2 Answers2

1

There is an Intent for Locale changed action. You should register BroadcastReceiver to catch this Intent and do whatever you want in onReceive() method.

Evgeniy Mishustin
  • 3,343
  • 3
  • 42
  • 81
0

I have a workaround but do this in all you activities

/**
*create BroadcastReciever to listen for local changes
**/
private BroadcastReceiver myReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                String locale = Locale.getDefault().getCountry();
                finish();
            }
        };


/**
* Register to BroadcastReciever on Resume
**/
 @Override
    protected void onResume() {

        IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED);
        registerReceiver(myReceiver, filter);
        Log.d(TAG,"resume");
        super.onResume();
    }

/**
* unsubscribe from BroadcastReciever onDestroy
**/

@Override
    protected void onDestroy() {

        try {
            unregisterReceiver(myReceiver);
        } catch(IllegalArgumentException e) {
            Log.d(TAG,"RECIEVER UNREGISTER ERROR");
        }
        super.onDestroy();

    }
Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55