Getting multiple broadcasts from intents?

左心房为你撑大大i 提交于 2019-11-29 07:35:10
Robert

First, you have a new BroadcastReceiver(){ every time you call sendSMS, so they pile up, one more each time you call sendSMS. You could add unregister(this); at the bottom of each BroadcastReceiver but better would be to move the Broadcast receiver out of this function. You can create+register one in onResume() and unregister it in onPause().

Second, read this link

if you ever want to send data along with your pendingIntent you need to help Android distinguish your pending intents better ...
e.g.

 PendingIntent deliveredPI = PendingIntent.getBroadcast(this, uniqueIdPerSMS++,
    new Intent(DELIVERED), PendingIntent.FLAG_CANCEL_CURRENT);

The simple this is that use a unique id for each deliveredPI, because if you do not then android considers all the same and for all the sms's the deliveredPi will show the result of any one( do not know if first or last).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!