6

在 Receiver 类或 Activity 类中是否可以在意图时获取 requestCode?

这是我未决的意图

alarmMgr= (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                Intent intent = new Intent(this, BroadcastReceiver_Class.class);
                /*intent.putExtra("alarm_time_minutes", minutes);*/
                pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent,requestCode);
                alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);

提前致谢..

4

1 回答 1

10

您可以将requestCode更多内容添加到您的意图中。如下:

intent.putExtra("requestCode", requestCode);

然后您可以通过以下方式在 Activity 类中获取它:

int requestCode = received_intent.getExtras().getInt("requestCode");  
于 2012-11-27T14:31:26.917 回答