android PengdingIntent Extras資訊

來源:互聯網
上載者:User
keywords:android PengdingIntent intent Extras資訊

發送通知時我們通常會在通知欄附加上一些資訊,當通過通知啟動某個activity時,利用這些附加資訊完成某些工作,但是會遇到這類問題:在通過通知啟動的activity無法擷取到intent的附加資訊,或者是擷取的附加資訊跟自己期望的不一致,不然你不間斷的發通知,每個通知附加資訊不一樣。

n.contentIntent = PendingIntent.getActivity(getApplicationContext(), (int) info.pId, intent,PendingIntent.FLAG_UPDATE_CURRENT);

藍色標記的切忌不能隨便弄個參數糊弄。看最後解釋。

之所以會犯這類錯大多人估計都被PendingIntent的getActivity的requestCode這個參數的注釋誤導了。雖然google說它暫時沒用,但是通過實踐和google後,發現這個參數很有用

解釋如下

Anroid reuses intents, the intent action and request code make it unique, but not the extra data. So you need to set a unique request id or use different intent actions. – Bachi Aug 15 '11 at 11:58

http://stackoverflow.com/questions/1198558/how-to-send-parameters-from-a-notification-click-to-an-activity

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.