PendingIntent does not send Intent extras

前端 未结 3 1255
眼角桃花
眼角桃花 2020-12-02 07:54

My MainActicity starts RefreshService with a Intent which has a boolean extra called isNextWeek.

My

3条回答
  •  有刺的猬
    2020-12-02 08:40

    I think you need to update the Intent when you receive a new one by overriding onNewIntent(Intent) in your Activity. Add the following to your Activity:

    @Override
    public void onNewIntent(Intent newIntent) {
        this.setIntent(newIntent);
    
        // Now getIntent() returns the updated Intent
        isNextWeek = getIntent().getBooleanExtra(IS_NEXT_WEEK, false);        
    }
    

    Edit:

    This is needed only if your Activity has already been started when the intent is received. If your activity is started (and not just resumed) by the intent, then the problem is elsewhere and my suggestion may not fix it.

提交回复
热议问题