I start a service using alarm manager using button click. It is working too. I have done it this way:
Intent scheduleSMS = new Intent(SMSProjectDatabase.this,SendSMS.class);
PendingIntent pendingIntent = PendingIntent.getService(SMSProjectDatabase.this,0, scheduleSMS,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND,(int)GeneralUtil.calculateTimeDifference(getApplicationContext()));
Log.i("SMS is scheduled after ",""+GeneralUtil.calculateTimeDifference(getApplicationContext()));
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Here SendSMS is a service that will be started by the alarm manager. But this is not how i want to start a service in my code. I want to Use the Alarmmanager to trigger a broadcast for the Broadcastreceiver. The Broadcastreceiver then starts the Service for me.
My BroadCast Receiver is
public class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
//here i want to start the service through the alarm manager
}
}
But i donno how am i supposed to do this.Please provide the appropriate solution for me to solve this problelm.
You just simply need to put your stuff for calling
ServiceusingAlarmManagerinside theonReceive()