Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 2024

Subscribe to real-time events

Amplify Android v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Android to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

Subscribe to mutations for creating real-time clients:

ApiOperation subscription = Amplify.API.subscribe(
ModelSubscription.onCreate(Todo.class),
onEstablished -> Log.i("ApiQuickStart", "Subscription established"),
onCreated -> Log.i("ApiQuickStart", "Todo create subscription received: " + ((Todo) onCreated.getData()).getName()),
onFailure -> Log.e("ApiQuickStart", "Subscription failed", onFailure),
() -> Log.i("ApiQuickStart", "Subscription completed")
);
// Cancel the subscription listener when you're finished with it
subscription.cancel();
val subscription = Amplify.API.subscribe(
ModelSubscription.onCreate(Todo::class.java),
{ Log.i("ApiQuickStart", "Subscription established") },
{ Log.i("ApiQuickStart", "Todo create subscription received: ${(it.data as Todo).name}") },
{ Log.e("ApiQuickStart", "Subscription failed", it) },
{ Log.i("ApiQuickStart", "Subscription completed") }
)
// Cancel the subscription listener when you're finished with it
subscription.cancel();
val job = activityScope.launch {
try {
Amplify.API.subscribe(ModelSubscription.onCreate(Todo::class.java))
.catch { Log.e("ApiQuickStart", "Error on subscription", it) }
.collect { Log.i("ApiQuickStart", "Todo created! ${it.data.name}") }
} catch (notEstablished: ApiException) {
Log.e("ApiQuickStart", "Subscription not established", it)
}
}
// When done with subscription
job.cancel()
RxSubscriptionOperation<? extends GraphQLResponse<?>> subscription =
RxAmplify.API.subscribe(request);
subscription
.observeConnectionState()
.subscribe(connectionStateEvent -> Log.i("ApiQuickStart", String.valueOf(connectionStateEvent)));
subscription
.observeSubscriptionData()
.subscribe(
data -> Log.i("ApiQuickStart", data),
exception -> Log.e("ApiQuickStart", "Subscription failed.", exception),
() -> Log.i("ApiQuickStart", "Subscription completed.")
);
// Cancel the subscription listener when you're finished with it
subscription.cancel();