class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
doSth();
}
}
在主要活动中:
Intent intentA = new Intent(MainApplication.getAppContext(), Receiver.class);
Intent intentB = new Intent(MainApplication.getAppContext(), Receiver.class);
PendingIntent pendingIntentA = PendingIntent
.getBroadcast(MainApplication.getAppContext(),0,intentA,0);
PendingIntent pendingIntentB = PendingIntent
.getBroadcast(MainApplication.getAppContext(),0,intentB,0);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
60000, pendingIntentA);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
60000, pendingIntentB);
在函数doSth()中,我想知道是由intentA还是intentB触发了该广播,如何在没有明确将其他信息放入intent中的情况下执行此操作?
答案 0 :(得分:1)
不能。由于Intent
完全相同,因此PendingIntent
也完全相同。您需要在Intent
中添加一些内容以进行区分:Intent
ACTION,Intent
DATA或某些“附加”。