重启Android App

作者: 一点墨汁 | 来源:发表于2017-06-07 12:59 被阅读347次

根据系统语言的变化来决定时候重新启动App

 <activity
            android:name=".MainActivity"
            android:launchMode="singleTask"
            ...
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
// check whether restart app or not
        String saveLocal = PreferencesUtil.getInstance(this).getLocal();
        String currentLocal = Locale.getDefault().getLanguage();
        if (!currentLocal.equals(saveLocal)) {

            PreferencesUtil.getInstance(this).saveLocal(currentLocal);
            if (saveLocal != null) {
//                Log.d("lpftag", "restart self");
                Intent killIntent = new Intent(this,MainActivity.class);
                killIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(killIntent);
                android.os.Process.killProcess(android.os.Process.myPid());
                System.exit(0);
            }
            return;
        }

相关文章

网友评论

    本文标题:重启Android App

    本文链接:https://www.haomeiwen.com/subject/qswofxtx.html