使用AlarmManager启动Android应用程序

4
我很新于Android,计划制作一个可以在特定时间启动的应用程序。我已经了解了AlarmManager、意图和广播接收器的相关知识。我已经看过并运行了一些来自其他线程的示例代码,并且能够运行它们。这些示例通过Toast发送通知和文本。

但是我的问题是,是否可以使用AlarmManager在我设置的时间启动我的应用程序,即显示我的应用程序的主屏幕?如果可以,我该如何做到这一点?

非常感谢您的帮助。

提前致谢。


展示你目前编写的代码。 - injecteer
是的,这是可能的,但你尝试了什么? - Kaveesh Kanwal
1个回答

3

是的,这是可能的。以下代码适用于我。

Intent intent = new Intent(this, YOUR_MAIN_ACTIVITY.class);
intent.setAction(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ID,
                        intent, 0);

final long DELAY_IN_MILLIS = DELAY_IN_MILLI_SECONDS+ System.currentTimeMillis();
AlarmManager alarmManager = (AlarmManager)
getSystemService(Activity.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, DELAY_IN_MILLIS,pendingIntent);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接