【问题标题】:Second BroadCast Receiver Does Not Run第二个广播接收器不运行
【发布时间】:2017-03-22 14:02:42
【问题描述】:

我编写了一个程序,希望在一个警报管理器中运行两个广播接收器类。 第一类是 MyReceiver,第二类是 RequestReciever ... 第一个运行但第二个没有运行...为什么?你能帮助我吗... 我的闹钟经理打电话

 private void workingAlaramManager() {
    //enable onRecieve method in broadcast reciever to report and get action in listener
    Intent intent = new Intent(getContext(), MyReceiver.class);
    Intent requestIntent=new Intent(getContext(),RequestReciever.class);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent pendingIntentRequest = PendingIntent.getBroadcast(getContext(), 1, requestIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, 1000, pendingIntent);
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, 1000, pendingIntentRequest);

}

我的第一堂课

public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
private GPSLocation gpsLocation;
private ApiManager apiManager;
private Activity activity;
private Context context;
private SharedPref sharedPref;
@Override
public void onReceive(Context context, Intent intent) {
    this.context=context;
    activity=new MainAccountActivity();
    apiManager = new ApiManager();
    sharedPref=new SharedPref(apiManager.deliveryPartner,apiManager.deliveryPartner.deliveryBike,context);
    sharedPref.loadData();
    getLatAndLng();
    getDataTime();
    requestToReportDeliverySituation();
}

第二个没有运行:(

公共类 RequestReciever 扩展 BroadcastReceiver { 公共请求接收器(){

}

private ApiManager apiManager;
private Activity activity;
private Context context;
private SharedPref sharedPref;

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    activity = new MainAccountActivity();

    apiManager = new ApiManager();
    sharedPref = new SharedPref(apiManager.deliveryPartner, apiManager.deliveryPartner.deliveryBike, context);
    sharedPref.loadData();

    sendCheckDeliveryRequest();

}

帮我取悦我的朋友们...

【问题讨论】:

  • AndroidManifest.xml中是否添加了RequestReciever?
  • 另外,RequestReciever 有错别字,应该是RequestReceiver,确保它与 AndroidManifest.xml 中添加的名称匹配
  • 谢谢。它很有帮助:)
  • 那么我会添加它作为答案。

标签: android alarmmanager android-broadcastreceiver


【解决方案1】:

确保没有拼写错误,并且您的所有接收者都在AndroidManifest.xml注册。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 1970-01-01
    相关资源
    最近更新 更多