BroadcastReceiver or Messenger via Handler

前端 未结 1 1917
一生所求
一生所求 2020-12-29 08:13

I have an IntentService which need to pass a message to an Activity. I know two ways of doing so.

  1. use sendBroadcast()

相关标签:
1条回答
  • 2020-12-29 08:22

    If your IntentService does not know whether the activity will exist (e.g., might have been destroyed), or if there are multiple activities that might be in the foreground and would want to know about what's going on, I'd use sendOrderedBroadcast(). You can arrange to then also have a "backstop" BroadcastReceiver that could raise a Notification, if desired, as I outline in this blog post and demonstrate in this sample project.

    Either of your techniques can work, though.

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