Java 单击按钮时重新启动应用程序

Java 单击按钮时重新启动应用程序,java,android,android-activity,Java,Android,Android Activity,我需要我的应用程序重新启动时,点击一个按钮,为更多的信息,我需要模拟,而不是我按下后退键,并再次打开应用程序。 我希望我可以用finish()关闭应用程序但如何再次启动onCrete()? 还有别的办法吗 谢谢使用意图呼叫您的活动。它将再次启动该活动 Intent intent = new Intent(MyActivity.this, MyActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //this will a

我需要我的应用程序重新启动时,点击一个按钮,为更多的信息,我需要模拟,而不是我按下后退键,并再次打开应用程序。 我希望我可以用
finish()关闭应用程序但如何再次启动
onCrete()
? 还有别的办法吗


谢谢

使用意图呼叫您的活动。它将再次启动该活动

Intent intent = new Intent(MyActivity.this, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //this will always start your activity as a new task
startActivity(intent);
您还可以在清单中添加,
android:launchMode=“singleTask”
,以便在任何时候只维护一个活动实例


同样:)

要重新启动应用程序,您可以在退出应用程序后使用alarm manager打开活动

AlarmManager alm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0));
android.os.Process.sendSignal(android.os.Process.myPid(), android.os.Process.SIGNAL_KILL);
startActivity()与“完成您的工作…”。。
AlarmManager alm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0));
android.os.Process.sendSignal(android.os.Process.myPid(), android.os.Process.SIGNAL_KILL);