Reputation: 5854
I've created alarm for each event in calendar while created. It works fine. Now if i set an event for 6pm and if i switch off and switch on the device, the alarm is ringing suddenly when the device is switched on. the alarm is not ringing for the event set time. My code for OnBootReceiver as follows:
@Override
public void onReceive(Context context, Intent intent)
{
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, AlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(context, ap.id1,i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime(),PERIOD,pi);
}
Upvotes: 1
Views: 458
Reputation: 21929
First of all save that timings in one databse
call a broad cast reveiver class like below
use below code in manifest file
<receiver android:name=".main.SampleOnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
in above code SampleOnBootReceiver
is acalss which extends from BroadcastReceiver
.
in that class u take alaram time from saved databse and set the alaram
Upvotes: 2