Skip to Content
Native Mobile Development
book

Native Mobile Development

by Shaun Lewis, Mike Dunn
November 2019
Intermediate to advanced
394 pages
9h 44m
English
O'Reilly Media, Inc.
Content preview from Native Mobile Development

Chapter 5. Message Passing

Message passing is a very broad and sometimes contentious topic in computer science, and there are many patterns and systems that have come and gone or abided, like “pub/sub” (“publish” and “subscribe”), event dispatchers, callbacks, observers, message queues, etc. The truth is, these are often very similar, and you’d be hard pressed to define practical differences between some of them. Regardless, this is a critical function in any application, and there are some consensus strategies in mobile application development that we’ll explain here.

Tasks

In this chapter, you’ll learn to:

  1. Use a callback to react to an operation.

  2. Dispatch a message to any interested subscribers.

  3. Listen for and react to messages dispatched within a system.

Android

In Android, you usually use callbacks for direct message passing and dispatch events with the statistically available and thread-safe LocalBroadcastManager. Note that LocalBroadcastManager sends Intent instances to be received by BroadcastReceiver instances—this is the same mechanism used by system-wide messages, many provided by other apps or operating system components; however, LocalBroadcastManager only notifies BroadcastReceivers in your app, which is both a good thing (safe) but also a little limiting—if you want to communicate between apps or with the underlying framework, you have to go beyond the brevity and simple API provided by LocalBroadcastManager.

Use a Callback to React to an Operation

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Wallace Wang
Ionic in Action

Ionic in Action

Jeremy Wilken
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781492052869Errata PageSupplemental Content