第一种
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ComponentName cn = new ComponentName(MyApplication.getContext().getPackageName(), LoginActivity.class.getName());
i.setComponent(cn);
MyApplication.getContext().startActivity(i);
第二种
Intent intent = new Intent(context, MainActivity.class);
PendingIntent restartIntent = PendingIntent.getActivity(
context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
//退出程序
AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
restartIntent); // 1秒钟后重启应用
android.os.Process.killProcess(android.os.Process.myPid());
android 程序崩溃后重启
最新推荐文章于 2024-08-10 04:06:28 发布