重启Android App

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

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