Page updated Nov 15, 2023

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.

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();
1ApiOperation subscription = Amplify.API.subscribe(
2 ModelSubscription.onCreate(Todo.class),
3 onEstablished -> Log.i("ApiQuickStart", "Subscription established"),
4 onCreated -> Log.i("ApiQuickStart", "Todo create subscription received: " + ((Todo) onCreated.getData()).getName()),
5 onFailure -> Log.e("ApiQuickStart", "Subscription failed", onFailure),
6 () -> Log.i("ApiQuickStart", "Subscription completed")
7);
8
9// Cancel the subscription listener when you're finished with it
10subscription.cancel();