Hi,
I’ve tried to implement Backendless Push Services to my Android app but it occasionally ( 2-3 out of 10 times, roughly) crashes the app at the stage of initial registration.
My concern isn’t why registration fails, rather the app works and opens.
If it couldn’t register, then let it be; whenever it finds the opportunity, it’ll register the device and starts to receive push notifications.
Unfortunately, it isn’t the story in my case.
Before the code samples and details, I’d like to ask that should I call the Backendless.Messaging.registerDevice() function every time the app starts as the Backendless.initApp() or should I check the registration status and register if and only it needs?
Ok, details…
This fails and crashes the app:
Backendless.Messaging.registerDevice( ArkConstants.gcmSenderID );
This, too, fails and crashes the app because somehow the exception thrown cannot be catch:
try {
Backendless.Messaging.registerDevice( ArkConstants.gcmSenderID );
} catch ( Exception e ) { e.printStackTrace(); }
And this, also, fails and the error / exception cannot be caught in the handleFault():
Backendless.Messaging.registerDevice( ArkConstants.gcmSenderID, null, new AsyncCallback<Void>() {
@Override
public void handleResponse ( Void response ) {}
@Override
public void handleFault(BackendlessFault fault) {
Log.v("kpTag", fault.getCode() );
Log.v("kpTag", fault.getMessage() );
Log.v("kpTag", fault.getDetail() );
}
});
Tried to throw a RuntimeException myself and it’s getting caught:
try {
throwAnErrorForMe();
} catch ( Exception e ) { e.printStackTrace(); }
private void throwAnErrorForMe () {
throw new RuntimeException( "A Sample RuntimeException" );
}
As I’ve stated above, I don’t care much for the reasons of failure; what I want is that the service fails gracefully and do not crash my app completely.
But still, here are two logs of the many different errors:
E/AndroidRuntime: FATAL EXCEPTION: IntentService[BackendlessPushService]
Process: com.kqapius.SAMPLEAPP, PID: 2397
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:67)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kqapius.SAMPLEAPP, PID: 9337
java.lang.RuntimeException: Could not register device on Backendless server: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Can't call rollback when autocommit=true
at com.backendless.push.BackendlessPushService.onError(BackendlessPushService.java:88)
at com.backendless.push.BackendlessPushService$1.handleFault(BackendlessPushService.java:252)
at com.backendless.Messaging$2.handleFault(Messaging.java:247)
at com.backendless.async.message.AsyncMessage$FaultHandler.handle(AsyncMessage.java:83)
at com.backendless.async.message.AsyncMessage.handleCallback(AsyncMessage.java:41)
at com.backendless.core.AndroidCarrier$1.handleMessage(AndroidCarrier.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
Please find the code of main activity of my app attached including the push registration logic.
Thanks,
~ Fatih
BaseApplication.txt (2.16kB)