简体   繁体   English

呼叫警报管理器时,带有附加功能的待定意图不起作用

[英]Pending Intents with extras not working when calling Alarm Manager

I have looked at many examples here of people having a similar problem with passing extras, but I still don't see my problem. 我在这里看到了很多例子,这些人在传递额外费用时遇到类似的问题,但我仍然看不到我的问题。

Here is my code where I set up my extras: 这是我设置附加功能的代码:

            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 );

Here is where I am getting them in onCreate() 这是我在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 doesn't get set. playMusicFlag未设置。 playSongs and showStopAlarm are not called. 不会调用pl​​aySongs和showStopAlarm。 Can someone tell me what I am doing wrong here? 有人可以告诉我我在做什么错吗?

Log your playMusicFlag String and check indeed are you getting any value and then compare your string; 记录您的playMusicFlag字符串,并检查确实获得任何值,然后比较您的字符串;

this way: 这条路:

if (playMusicFlag.equalsIgnoreCase("Y"))

Instead: 代替:

if (playMusicFlag == "Y") 

use like this while retriving 检索时像这样使用

intent.getExtras().getString("playMusic");

i think it works. 我认为它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM