The Android™ API is bundled in a JAR file and is supported
on Android KitKat and later.
Get the Android SDK as a JAR:
To compile the Diffusion Android APK, add the following to the build.gradle
file within your project:
Table 1. Supported platforms and transport protocols for the
||Minimum supported versions
||Supported transport protocols
||API 19 / v4.4 / KitKat and later
Note: Push Technology provides
only best-effort support for Jelly Bean (API 16-18, v4.1-4.3).
Considerations and capabilities that are specific to the Android
- Diffusion™ Cloud connections
- Ensure that you use the asynchronous open() method with a callback.
Using the synchronous open() method might open a connection on the
same thread as the UI and cause a runtime exception. However, the synchronous
open() method can be used in any thread that is not the UI
- Applications in background state
Android applications can be sent to the background
and their activity stopped. When this happens your application is notified by the
onStop() callback of the Android
Activity class. An application's activity can be stopped when the
user switches to another application, starts a new activity from within the
application, or receives a phone call.
When your application's activity is stopped, we recommend that it saves its state
locally – in particular, any topic subscriptions it has made – and closes
its client session with Diffusion Cloud. When the Diffusion Cloud app returns to the foreground, open a new client
session with Diffusion Cloud and use the saved state to restore
For more information, see the Android Activity
Lifecycle documentation and Stopping and Restarting an Activity.
- Writing good callbacks
- The Android client library invokes callbacks using a
thread from Diffusion Cloud thread pool. Callbacks for a particular
session are called in order, one at a time. Consider the following when writing
- Do not sleep or call blocking operations in a callback. If you do so, other
pending callbacks for the session are delayed. If you must call a blocking
operation, schedule it in a separate application thread.
- You can use the full Diffusion Cloud API to make other
requests to the server. If you want to make many requests based on a single callback
notification, be aware that Diffusion Cloud client flow control
is managed differently in callback threads. Less throttling is applied and it is
easier to overflow the servers by issuing many thousands of requests. If you have a
lot of requests to make, it is better to schedule the work in an application
- Regular expressions
- The Android client uses the same regular expression
engine to Diffusion Cloud. Some regular expressions in topic selectors
are evaluated on the client and others on Diffusion Cloud. There is no
difference in how these regular expressions are evaluated in the Android client.