Activity啓動之後獲取不到傳過來的Intent

當Activity A啓動過之後回到後臺,且是singleTask模式,然後從另一個Activity B通過startActivity(Intent)啓動,之後會出現獲取不到我們想要的intent中所傳數據的情況,這時候我們只需要重寫onNewIntent方法即可


//此方法在onResume之前執行
@Override
protected void onNewIntent(Intent intent) {
    //每次重新到前臺就主動更新intent並保存,之後就能獲取到最新的intent
    setIntent(intent); 
    super.onNewIntent(intent);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章