android - How could Intent be null in onHandleIntent()? -
my android app crashes , logcat :-
java.lang.nullpointerexception @ com.google.android.gcm.gcmbaseintentservice.onhandleintent(gcmbaseintentservice.java:194) @ android.app.intentservice$servicehandler.handlemessage(intentservice.java:65) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.os.handlerthread.run(handlerthread.java:60)
i looked android gcm r3 source , found argument intent null in onhandleintent().
is possible? how fix it?
(i know null intent seen service.onstartcopmmand
returning start_sticky
intentservice.onstartcommand
doesn't use start_sticky
.)
i think application crashes in devices during installation time. it's because during installation gcm service receives intent
other google source , broadcast receiver not prepared handle type of intent
.
if want receive gcm intent want pull server through push notification, use in handle intent call.
protected void onhandleintent(intent intent) { bundle extras = intent.getextras(); //string msg = intent.getstringextra("message"); string from=extras.getstring("from"); googlecloudmessaging gcm = googlecloudmessaging.getinstance(this); string messagetype = gcm.getmessagetype(intent); if (!extras.isempty()) { if (googlecloudmessaging.message_type_send_error.equals(messagetype)) { senderrornotification("send error: " + extras.tostring()); } else if (googlecloudmessaging.message_type_deleted.equals(messagetype)) { senderrornotification("deleted messages on server: " + extras.tostring()); // if it's regular gcm message, work. } else if (googlecloudmessaging.message_type_message.equals(messagetype)) { // loop represents service doing work. (int = 0; < 5; i++) { log.i(tag, "working... " + (i + 1) + "/5 @ " + systemclock.elapsedrealtime()); try { thread.sleep(500); } catch (interruptedexception e) { } } log.i(tag, "completed work @ " + systemclock.elapsedrealtime()); // post notification of received message. // sendnotification("received: " + extras.tostring()); /*********error in devices*****************/ if(from.equals("google.com/iid")) { //related google ... not perform action } else { //handle received notification string msg = intent.getstringextra("message"); sendnotification(msg); log.i(tag, "received: " + extras.tostring()); } /**************************/ } } gcmbroadcastreceiver.completewakefulintent(intent); }
Comments
Post a Comment