Android 重启应用代码

//重启应用
                final Intent launchIntent = getApplication().getPackageManager().getLaunchIntentForPackage(getPackageName());
                if (launchIntent != null) {
                    UIUtils.showToastSafe("应用正在重启中请稍后...");
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(launchIntent);
                            //添加activity切换动画效果
                            overridePendingTransition(0, 0);
                            ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                            am.killBackgroundProcesses("你的包名");
                            android.os.Process.killProcess(android.os.Process.myPid());
                            System.exit(0);
                            finish();
                        }
                    },400);

你可能感兴趣的:(android)