我编写了一个想要在一个报警管理器中运行两个BroadCast接收器类的程序。 第一类是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 { public RequestReciever(){
}
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();
}
帮助我取悦我的朋友......
答案 0 :(得分:0)
确保没有拼写错误且所有接收者都在AndroidManifest.xml
注册。