Android
The Android™ API is bundled in a JAR file and is supported on Android KitKat and later.
apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { multiDexEnabled true applicationId "com.pushtechnology.android.example" minSdkVersion 19 targetSdkVersion 27 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { maven { url "https://download.diffusiondata.com/maven/" } } dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9' implementation 'org.slf4j:slf4j-api:1.7.21' implementation 'com.pushtechnology.diffusion:diffusion-android-client:6.11.2' }
Capabilities
To see the full list of capabilities supported by the Android API, see Feature support in the Diffusion API.
Support
Platform | Minimum supported versions | Supported transport protocols |
---|---|---|
Android | API 19 / v4.4 / KitKat and later
Note: DiffusionData provides
only best-effort support for Jelly Bean (API 16-18, v4.1-4.3).
|
WebSocket HTTP (polling) |
Resources
Using
Considerations and capabilities that are specific to the Android API
- Diffusion™ 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 thread.
- 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 the Diffusion server . When the Diffusion app returns to the foreground, open a new client session with the Diffusion server and use the saved state to restore topic subscriptions.
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
thread pool. Callbacks for a particular
session are called in order, one at a time. Consider the following when writing
callbacks:
- 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 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 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 thread.
- Regular expressions
- The Android client uses the same regular expression engine to the Diffusion server . Some regular expressions in topic selectors are evaluated on the client and others on the Diffusion server . There is no difference in how these regular expressions are evaluated in the Android client.