重启Android App

根据系统语言的变化来决定时候重新启动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 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,335评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,937评论 18 139
  • 玛丽雪莱的《弗兰肯斯坦》是我最喜欢的一个科幻故事,没有之一。记得有一年高中的一个下午,学校停课,家长上班去了,我偷...
    OScarsab阅读 1,568评论 0 0
  • 精油是世界上最小的美容分子,被誉为液体的荷尔蒙,它比其他护肤品高出70倍的吸收力,3分钟到达真皮层,5分钟渗透到血...
    lucas红阅读 556评论 0 0
  • 儿子上小学五年级,放暑假已经有几天了,学校却忽然通知所有家长到校。原来是为了签订一份暑期安全协议,并且建了微信群,...
    b8a5a7d67891阅读 228评论 0 0