2012-06-29 57 views
0

我正在制作闹钟应用程序。这个应用程序在警报处于活动状态(由日历激活)时调用一个意图。当闹钟或日历关闭时,我想打电话给hello.class。这个类在被日历调用的未决意图中提及。当日历被调用并且待处理的意图应该被处理时,根本没有任何事情发生。关于我做错什么的想法?Android日历意图

我的代码如下:标有“ABC”的注释该生产线是其中hello.class提到

Intent myIntent = new Intent(AndroidAlarmService.this, Hello.class); // ABC 


pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0); 

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 

Calendar calendar = Calendar.getInstance(); 
calendar.setTimeInMillis(System.currentTimeMillis()); 

calendar.add(Calendar.SECOND, 5); 
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); 
+0

这或许能有所帮助:HTTP://stackoverflow.com/questions/3052149/using-alarmmanager-在特定时间启动服务 –

回答

1

您必须添加FLAG_ACTIVITY_NEW_TASK到你的意图,因为活动将的上下文之外推出现有的活动。

该文件说明如此。

只需添加

myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

下面Intent myIntent = new Intent...

,并更改PendingIntent.getService(...)PendingIntent.getActivity(...)

+0

如果您能给我一些示例代码以查找它的位置,我们将不胜感激,对不起,我仍然只是初学者。 –

+0

非常感谢:) –