如何在区域设置更改中销毁应用程序

时间:2016-12-21 11:11:48

标签: android locale

在我的多语言应用程序中,我想从启动器活动中重新启动我的应用程序。但我无法这样做。我已经通过删除

更改了应用程序清单
  

区域设置

来自

  

机器人:configChanges ="取向| keyboardHidden"

但它不适合我。 的清单:

 <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>

2 个答案:

答案 0 :(得分:1)

有一个Intent  对于Locale更改的操作。 您应该注册BroadcastReceiver以捕获此Intent,并在onReceive()方法中执行任何操作。

答案 1 :(得分:0)

我有一个解决方法,但在所有活动中都这样做

/**
*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();

    }