Using this code, I try to set alarmmanager to stars Notify.class at 25/12/2012 – 15.15 but when I use this code no Notify.class starts. Where’s the problem?
Calendar cal = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault());
cal.set(Calendar.DATE,25);
cal.set(Calendar.MONTH,Calendar.DECEMBER);
cal.set(Calendar.YEAR,2012);
cal.set(Calendar.HOUR_OF_DAY, 15);
cal.set(Calendar.MINUTE, 15);
cal.set(Calendar.SECOND, 00);
Intent intent3 = new Intent(context, Notify.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,intent3, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
Manifest:
<activity android:name="Notify"></activity>
<receiver android:name="AlarmReceiver" >
<intent-filter>
<action android:name="com.example.AlarmReceiver" />
</intent-filter>
you should write this
You have switched android:name for receiver and it’s intent filter. You may replace com.example.AlarmReceiver with .AlarmReceiver
after you have made this change in your manifest, whatever code you have written inside onReceive() method of your broadcast receiver com.example.AlarmReceiver will get executed.
What your code will do is it will set alarm manager for the specified date-time. At that moment it will fire an intent with action name AlarmReceiver. Your Broadcast receiver is in Manifest so it will catch the broadcast and execute it’s onReceive() Method.
If you want to start an activity write context.startActivity(…) inside onReceive().
Edit: also change your intent to this: