Cancel Device Registration¶
To cancel the registration of a device with Backendless, an application can use the API described below:
Blocking API¶
// unregisters device from all Backendless messaging channels
public void unregisterDevice() throws BackendlessException;
// unregisters device from the specified Backendless messaging channels
public void unregisterDevice( List<String> channels )
Non-Blocking API¶
// unregisters device from all Backendless messaging channels
public void unregisterDevice( AsyncCallback<Integer> callback ) throws BackendlessException;
// unregisters device from the specified Backendless messaging channels
public void unregisterDevice( List<String> channels, AsyncCallback<Integer> callback )
Return value (non-blocking methods)¶
The callback
argument generic type for the non-blocking methods is Java Integer
. The value is delivered to the handleResponse
method of the callback and identifies the number of channels which the device is still registered with in Backendless. This information is helpful to determine if the device should also be unregistered from FCM. When the number of remaining registrations in Backendless is zero, in some cases it might be needed to unregister from FCM as well.
Errors¶
The following errors may occur during the device registration cancellation API callThe following errors may occur during the device registration API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error:
Error Code |
Description |
---|---|
5001 |
Unable to cancel device registration - unknown device ID. |
Example¶
String applicationID = "YOUR-APP-ID";
String apiKey = "ANDROID-KEY";
// this call must be somewhere early on in the application initialization
Backendless.initApp( appContextOrActivity, applicationId, apiKey );
try
{
Backendless.Messaging.unregisterDevice();
}
catch( BackendlessException exception )
{
// either device is not registered or an error occurred during de-registration
}
Codeless Reference¶
Returns the integer value identifying the number of channels which the device is still registered with in Backendless. This information is helpful to determine if the device should also be unregistered from FCM. When the number of remaining registrations in Backendless is zero, in some cases it might be needed to unregister from FCM as well.
The example below cancels the registration of a device with Backendless: