Using Intents or an event bus to communicate within the same app

一曲冷凌霜 提交于 2019-12-02 20:15:51

Pros for using Otto:

  • You get to design your own event types, versus having to use custom actions or something to distinguish one Intent from another

  • Everything is within your own process (contrast with startActivity() and kin, which always involve IPC, even if the activity you are starting is in your own app), for speed and security

  • A bit less coding, as you aren't having to instantiate IntentFilter or BroadcastReceiver objects

  • It offers the producer pattern (as a quasi-replacement for sticky broadcasts)

  • Being not part of the OS, it has the potential to be updated more frequently

Cons for using Otto:

  • It cannot start an activity

  • It cannot start a service

  • It cannot bind to a service

  • It cannot send a broadcast

  • It cannot be used in a PendingIntent or for any true IPC

IOW, the true comparison for Otto is with LocalBroadcastManager, not with the general use of Intents.

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