Android push app regiseration crashing app.

Hello Team, I am getting the following exception while device registration. Can you please look into this issue.

Fatal Exception: java.lang.RuntimeException: AUTHENTICATION_FAILED
at com.backendless.push.BackendlessPushService.onError(BackendlessPushService.java:88)
at com.backendless.push.BackendlessPushService.handleRegistration(BackendlessPushService.java:233)
at com.backendless.push.BackendlessPushService.handleIntent(BackendlessPushService.java:98)
at com.backendless.push.BackendlessPushService.onHandleIntent(BackendlessPushService.java:65)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)

Thanks
Raza

Hi Raza,

What version of Backendless SDK for Android do you use?

Regards,
Mark

Hello Mark,
Thanks fro the quick response. I am using the latest Backendless SDK v3.0.21 for Android.

Thanks
Raza

Hello @Hassan Raza,
Assuming you have read Push Messaging docs at https://github.com/Backendless/Android-SDK/blob/master/docs/push.md.
Default implantation of onError method shrows RuntimeException. You need to override this method in your implementation of BackenldessPushService.
Artur

Marked as duplicate of http://support.backendless.com/t/android-push-registration-crashes-app

Hello ARthur,

I have read that thread. The mentioned thread had an error in the AndroidManifest.xml as duplicate entry, with default and custom BackenldessPushService, but in my case I have verified it is only showing single default entry which is provided in the documentation. Please note that this error occurs occasionally for around 1/100 users, but it accumulatively it gets quite high.


<intent-filter>

    &lt;category android:name=&quot;com.thebestlivete.pkdintdpoe&quot; /&gt;
&lt;/intent-filter&gt;

</receiver>
<service android:name="com.backendless.push.BackendlessPushService" />

Regards
Raza

As you mentioned above that the default Default implantation of onError method shrows RuntimeException, please note that i have surrounded that with Try/Catch but it still is crashing the app, as per my knowledge, below mentioned implementation should now crash the app. Can you please guide how can i avoid application crash.

public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    Backendless.initApp(this, "xxxxxxxxxx", "xxxxxxxxxx", "v1");

    try {
        Backendless.Messaging.registerDevice("xxxxxxxxxx", new AsyncCallback&lt;Void&gt;() {
            @Override
            public void handleResponse(Void response) {
                // Device Registered Successfully
            }
            @Override
            public void handleFault(BackendlessFault fault) {
                // Device Not Registered Error
            }
        });
    } catch (Exception excep) {
        Log.d("MyApplication", excep.getMessage());
    }
}

}

Hi Hassan

It’s completely useless to wrap ‘registerDevice’ with try/catch

You have to tell the Backendless, that you want your own class to handle an incoming messages instead of the default one provided by Backendless (which means re-throwing all incoming errors)

To do this, you have to create and register a subclass of BackendlessPushService.
And the document, Arthur mentioned is exactly about this.

Hello Vitaly,

I have overridden the onError() method of BackendlessPushService as given below. Can you please guide me how can I catch the exception provided above, as I am still clueless. As all I want is not to crash the app, nothing else.

public class MyPushService extends BackendlessPushService {
@Override
public void onError(Context context, String message) {
Log.d(“MyApplication”, “Device Not Registered Error”);
}
}

Thanks
Raza

Now you need to register your custom class MyPushService instead of BackendlessPushService in your AnroidManifest.xml. This way when the error happens, it will be logged without throwing exception, because of the code you’ve written in onError:

Log.d("MyApplication", "Device Not Registered Error");

Thank you very much for excellent support.