当应用未运行时,推送消息会导致崩溃

时间:2016-02-14 21:50:35

标签: codenameone

我将谷歌GCM实现为原生,并且当应用程序在前台运行时正常运行。但是,如果应用程序在一段很长的空闲时间后没有运行,当推送消息进入时,虽然它被检测到,但会导致崩溃。我没有类PushReceiver.java所以这必须由CN1注入。这是堆栈跟踪:

02-14 22:50:14.796: W/System.err(21026): java.io.EOFException
02-14 22:50:14.796: W/System.err(21026):    at libcore.io.Streams.readFully(Streams.java:83)
02-14 22:50:14.796: W/System.err(21026):    at java.io.DataInputStream.readFully(DataInputStream.java:99)
02-14 22:50:14.796: W/System.err(21026):    at java.io.DataInputStream.decodeUTF(DataInputStream.java:178)
02-14 22:50:14.796: W/System.err(21026):    at java.io.DataInputStream.decodeUTF(DataInputStream.java:173)
02-14 22:50:14.796: W/System.err(21026):    at java.io.DataInputStream.readUTF(DataInputStream.java:169)
02-14 22:50:14.796: W/System.err(21026):    at com.codename1.impl.android.AndroidImplementation.getPendingPush(AndroidImplementation.java:381)
02-14 22:50:14.796: W/System.err(21026):    at com.rixma.mobile.PushReceiver.handleMessage(PushReceiver.java:162)
02-14 22:50:14.796: W/System.err(21026):    at com.rixma.mobile.PushReceiver.onReceive(PushReceiver.java:62)
02-14 22:50:14.796: W/System.err(21026):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3011)
02-14 22:50:14.796: W/System.err(21026):    at android.app.ActivityThread.access$1800(ActivityThread.java:177)
02-14 22:50:14.796: W/System.err(21026):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
02-14 22:50:14.796: W/System.err(21026):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-14 22:50:14.796: W/System.err(21026):    at android.os.Looper.loop(Looper.java:135)
02-14 22:50:14.796: W/System.err(21026):    at android.app.ActivityThread.main(ActivityThread.java:5910)
02-14 22:50:14.796: W/System.err(21026):    at java.lang.reflect.Method.invoke(Native Method)
02-14 22:50:14.806: W/System.err(21026):    at java.lang.reflect.Method.invoke(Method.java:372)
02-14 22:50:14.806: W/System.err(21026):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
02-14 22:50:14.806: W/System.err(21026):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
02-14 22:50:14.806: D/AndroidRuntime(21026): Shutting down VM
02-14 22:50:14.806: E/AndroidRuntime(21026): FATAL EXCEPTION: main
02-14 22:50:14.806: E/AndroidRuntime(21026): Process: com.rixma.mobile, PID: 21026
02-14 22:50:14.806: E/AndroidRuntime(21026): java.lang.RuntimeException: Unable to start receiver com.rixma.mobile.PushReceiver: java.lang.NullPointerException: Attempt to get length of null array
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3018)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.app.ActivityThread.access$1800(ActivityThread.java:177)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.os.Looper.loop(Looper.java:135)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.app.ActivityThread.main(ActivityThread.java:5910)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at java.lang.reflect.Method.invoke(Native Method)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at java.lang.reflect.Method.invoke(Method.java:372)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
02-14 22:50:14.806: E/AndroidRuntime(21026): Caused by: java.lang.NullPointerException: Attempt to get length of null array
02-14 22:50:14.806: E/AndroidRuntime(21026):    at com.rixma.mobile.PushReceiver.handleMessage(PushReceiver.java:163)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at com.rixma.mobile.PushReceiver.onReceive(PushReceiver.java:62)
02-14 22:50:14.806: E/AndroidRuntime(21026):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3011)
02-14 22:50:14.806: E/AndroidRuntime(21026):    ... 9 more

请建议如何解决这个问题,因为我似乎无法控制崩溃的代码,它似乎发生在CN1代码中。我应该使用这样的推送通知来唤醒“死亡”。应用程序,只要它没有被用户强行停止。

2 个答案:

答案 0 :(得分:1)

您没有添加代码,但只要您的接收过程与活动有关,当应用程序不在前台时就会出现问题,因为它们已经死了。 您应该在后台服务中处理所有进程。

答案 1 :(得分:0)

内置于Codename One的推送支持假定您正在使用Codename One推送。主要原因是跨设备,Android和Android的推送实现的碎片化。 iOS在这里完全不同。