PendingIntent 的 getBroadcast 和 getService

getBroadcast and getService of PendingIntent

getBroadcast和getService的requestCode请求码可以一样吗? 例如,

Intent intent = new Intent(INTENT_FILTER);
PendingIntent sender = PendingIntent.getBroadcast(ctx, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.cancel(sender);
sender.cancel();

Intent intentS = new Intent(ctx, MyService.class);
PendingIntent senderS = PendingIntent.getService(ctx, requestCode, intentS, PendingIntent.FLAG_CANCEL_CURRENT);

am.cancel(senderS);
senderS.cancel();

是的。因为还有其他因素可以用来区分PendingIntents。在您的情况下,sender 有一个 ACTION,而 senderS 没有 ACTION,但有一个组件(包和 class)。