class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
doSth();
}
}
In the main activity:
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);
In the function doSth() i want to know if this broadcast is triggered whether by intentA or intentB, how can i do that without explicitly putting additional information into the intent?, thanks in advance.
You can't. Because the Intent
s are exactly the same and because of that, the PendingIntent
s are also exactly the same. You will need to put something in the Intent
to differentiate: either the Intent
ACTION, Intent
DATA, or some "extras".