简体   繁体   English

没有调用BroadcastReceiver的onReceive方法

[英]BroadcastReceiver's onReceive method is not getting called

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: 我的清单在application标签内具有以下接收者标签:

<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? 有人可以告诉我为什么在我的设备时间到开始时间时无法调用onReceive吗?

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(). 我认为您需要PendingIntent.getBroadcast(),而不是PendingIntent.getActivity()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM