我在这里查看了很多人在传递额外内容时遇到类似问题的示例,但我仍然没有看到我的问题。
这是我设置附加功能的代码:
PLAY_MUSIC = "Y";
Intent intentAlarm = new Intent(this, MainActivity.class);
intentAlarm.putExtra("playMusic",PLAY_MUSIC);
intentAlarm.putExtra("mPos", mPos);
// 12345 is a request code
PendingIntent pIntent = PendingIntent.getActivity(this, 12345,
intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager)(this.getSystemService( Context.ALARM_SERVICE ));
am.set(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(), pIntent );
这是我在 onCreate() 中获取它们的地方
protected void onCreate(Bundle savedInstanceState) {
if (VERBOSE) Log.v(TAG, "+++ ON CREATE +++");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
playMusicFlag = intent.getStringExtra("playMusic");
mPos = intent.getIntExtra("mPos", 0);
if (playMusicFlag == "Y") {
if (VERBOSE) Log.v(TAG, "+++ playMusicFlag NOT SET+++");
playSongs();
showStopAlarmButton();
} // if
playMusicFlag 未设置。不调用 playSongs 和 showStopAlarm。有人可以告诉我我在这里做错了什么吗?