Remove a device
Use removeDevice to de-register the current device so that Amazon Connect journeys stop delivering notifications to it.
val result = client.removeDevice()removeDevice takes no arguments. The library resolves the device identifier for you, and your backend permits removal only of a device that the calling identity owns.
Sign a user out safely
Handle a failed removal deliberately rather than letting it block sign-out. The following pattern signs the user out even when de-registration fails, which avoids trapping a user in a signed-in state because of a network error:
import com.amplifyframework.foundation.result.Result
suspend fun handleSignOut() { val result = client.removeDevice() if (result is Result.Failure) { Log.w("SignOut", "Failed to remove device before sign out", result.error) }
Amplify.Auth.signOut { /* handle sign-out result */ }}When to call removeDevice
Call removeDevice in these situations:
- Before signing a user out, as described above.
- When a user turns off notifications in your application's settings.
- Before deleting a user's account.
You do not need to call removeDevice when the push token is replaced. Registration is keyed on a device identifier that is stable for the installation, so registering with a new token updates the existing record. See Register a device.
Register the device again
The device identifier persists after removal, so a user who opts back in can be registered again with registerDevice. Removing a device does not reset the identifier or require your application to store one.
Handle errors
removeDevice returns a Result that fails with a network, credentials, or service exception when the request cannot complete. When no device has ever been registered on this installation there is nothing to remove, so the call succeeds without contacting the endpoint.