1

I am trying to invoke certain function in my app at specific time every week. Here is what I did:

In my activity I have following code

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

PendingIntent pIntent;

//my function to get first invoke time
        long lAlarmStartTime = getAlarmStartTime(Calendar.SUNDAY, alrm);

Intent intentArg = new Intent(getApplicationContext(), RcvAlarms.class).putExtra    (ALARM_ALARM_ID,  alrm.getMy_id());

pIntent = PendingIntent.getActivity(getApplicationContext(),
                (int) task.getMy_id() * 10 + Calendar.SUNDAY,
                intentArg, flag);

am.setRepeating(AlarmManager.RTC_WAKEUP, lAlarmStartTime,
                AlarmManager.INTERVAL_DAY * 7, pIntent);

I have another another class:

public class RcvAlarms extends BroadcastReceiver {

public RcvAlarms() {
    // TODO Auto-generated constructor stub
}

@Override
public void onReceive(Context context, Intent intent) {//my job }

My manifest has the following receiver tag inside the application tag:

<receiver android:name=".RcvAlarms" android.text="Repeat Task Receiver"></receiver>

Could someone please tell me why onReceive is not getting invoked when my device time reaches start time?

user
  • 86,916
  • 18
  • 197
  • 190
Jais Joy
  • 81
  • 1
  • 5

1 Answers1

0

The code when you set the alarm is the code you'd use to have it launch an activity. I think you need PendingIntent.getBroadcast(), not PendingIntent.getActivity().

Jules
  • 14,841
  • 9
  • 83
  • 130
  • can you help http://stackoverflow.com/questions/39901321/is-it-possible-to-call-onreceive-method-from-a-dialog – AI. Oct 06 '16 at 17:24