// 重启应用
public void restartApp() {
Intent intent = new Intent();
// 参数1:包名,参数2:程序入口的activity
intent.setClassName(getPackageName(), "包名");
PendingIntent restartIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent,
Intent.FLAG_ACTIVITY_NEW_TASK);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
restartIntent); // 1秒钟后重启应用
finishProgram(); // 自定义方法,关闭当前打开的所有avtivity
}
2:第二种方式:
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);