Just a second...

Android

The Android™ API is bundled in a JAR file and is supported on Android Nougat (Android v7, API level 24), and later.

Note: DiffusionData does not guarantee to support any version of Android released after a minor version release. For example, Diffusion 6.9 won't always work with versions of Android released after 6.9.1.

To use the Diffusion Android APK within your Android Studio project, first ensure your project build configuration meets the minimum requirements of the library:

Table 1. Minimum project build configuration
Requirement Library contract
Java language Java 17
Gradle 8.7+ (In order to support Android Gradle Plugin at version below)
AGP 8.6.0+
Android runtime API 24+
Core library desugaring Required
desugar_jdk_libs 2.0.0+
compileSdk 30+

The Diffusion Android APK can then be declared as a dependency within your app level build.gradle file.

Because the APK is distributed as a jar file from the Diffusion servers, you’ll also need to include an additional maven repository within your gradle config. The best practice for doing so is to extend the settings.gradle file at the root of your Android Studio project.

build.gradle file:
dependencies {
    implementation 'com.pushtechnology.diffusion:diffusion-android-client:6.13.0'
    ...
}
settings.gradle file:
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url = "https://download.diffusiondata.com/maven/"
        }
    }
}

Capabilities

To see the full list of capabilities supported by the Android API, see Feature support in the Diffusion API.

Support

Table 2. Supported platforms and transport protocols for the client libraries
Platform Minimum supported versions Supported transport protocols
Android

Android 7 (API level 24)

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 Android Platform Activity documentation.

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.