Getting multiple broadcasts from intents?

后端 未结 2 1222
忘掉有多难
忘掉有多难 2020-12-18 07:48

http://mobiforge.com/developing/story/sms-messaging-android

I used the example code in the above link my own application for sending an SMS, but I run into a problem

相关标签:
2条回答
  • 2020-12-18 08:36

    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);
    
    0 讨论(0)
  • 2020-12-18 08:44

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

    0 讨论(0)
提交回复
热议问题