I always catch exceptions thrown by your methods but in two cases I see exceptions get thrown by your SDK without me catching them.
One is when I try to register a device - this happens sometimes. It might has something to do with registering a pre registered device.
The other time is when I receive a time out. Sometimes it wont come back to me as an exception and will just crash the app.
Lea, what platform do you use (Android, iOS)?
And could you provide some sample of your code? - This will help up to reproduce this problem.
android
Backendless.Messaging.registerDevice(Constants.GCM_SENDER_ID, new BackendlessCallback<Void>() {
@Override
public void handleResponse(Void response) {
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(BuildiApplication.this, "error registering device", Toast.LENGTH_SHORT).show();
}
});
Hi Lea,
Could you please provide some more information about the exception you get? A message, maybe?
When the app crashes you still can see a reason in LogCat.
07-13 15:00:55.179 25395-25395/com.example.bf_2.buildi E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bf_2.buildi, PID: 25395
java.lang.RuntimeException: Could not register device on Backendless server: Read timed out
at com.backendless.push.BackendlessBroadcastReceiver.onError(BackendlessBroadcastReceiver.java:148)
at com.backendless.push.BackendlessBroadcastReceiver$1.handleFault(BackendlessBroadcastReceiver.java:310)
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:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Does it happen when you have network problems?
no i have connection to network
If you look into the source code of BackendlessBroadcastReceiver, you will find a method called onError( Context, String ). In its default implementation, it throws a RuntimeException - this is exactly what you experience and why your app crashes.
In your implementation you may override this method and change the exception-throwing behaviour to something suiting your needs in case of an error.