使用Alarm Manager显示对话框

时间:2014-05-29 10:15:26

标签: android alarmmanager alarm android-alarms

我不知道如何设置闹钟以便在5秒后显示Alert Dialog让我做某事。

知道的人,

请帮助我,

谢谢,

p / s:我可以使用Alarm Manager重启应用程序,如下所示。

 public static void restartApplication(Context source, Context destination) {
        // Restart the application by using the way : Set alarm timer to
        // open the application again in a few seconds will be the better way
        PendingIntent mPi = PendingIntent.getActivity(source, 0, new Intent(
                new Intent(source, SplashScreen.class)), ((Activity) source)
                .getIntent().getFlags());
        AlarmManager mgr = (AlarmManager) ((Activity) source)
                .getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, mPi);
    }

1 个答案:

答案 0 :(得分:0)

您可以将Intent设置为向其传递一些参数的活动,以便在其onResume方法中显示对话框,例如:

Intent myIntent = new Intent(source, SplashScreen.class);
myIntent.putExtra("show_dialog",true);

PendingIntent mPi = PendingIntent.getActivity(source, 0,myIntent, ((Activity) source)
            .getIntent().getFlags());

希望有所帮助

相关问题