android - App crashes onResume when canceling Notification -
android - App crashes onResume when canceling Notification -
i seek cancel notification in onresume() crashes:
with displaynotification() create notification. tried set cancelnotification() in seek catch. doesn't solve problem. without can't start app generate notification.
here codesnippets:
onresume:
@override protected void onresume() //activity resumed , visible 1 time again { log.d(logtag,"onresume() called"); super.onresume(); cancelnotification(); }
cancelnotification():
protected void cancelnotification() { log.i("cancel", "notification"); mnotificationmanager.cancel(1); }
displaynotification():
protected void displaynotification(string message, string ticker) { log.i("start", "notification"); /* invoking default notification service */ notificationcompat.builder mbuilder = new notificationcompat.builder(this); mbuilder.setcontenttitle("neue nachricht!"); mbuilder.setcontenttext(message); mbuilder.setticker(ticker); mbuilder.setsmallicon(r.drawable.ic_launcher); /* increment notification number every time new notification arrives */ mbuilder.setnumber(++nummessages); /* creates explicit intent activity in app */ intent resultintent = new intent(this, mainactivity.class); taskstackbuilder stackbuilder = taskstackbuilder.create(this); stackbuilder.addparentstack(mainactivity.class); /* adds intent starts activity top of stack */ stackbuilder.addnextintent(resultintent); pendingintent resultpendingintent = stackbuilder.getpendingintent( 0, pendingintent.flag_update_current ); mbuilder.setcontentintent(resultpendingintent); mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); /* notificationid allows update notification later on. */ mnotificationmanager.notify(1, mbuilder.build()); }
error:
10-23 17:27:35.763: e/androidruntime(349): fatal exception: main 10-23 17:27:35.763: e/androidruntime(349): java.lang.runtimeexception: unable resume activity {com.example.blauzahn/com.example.blauzahn.mainactivity}: java.lang.nullpointerexception 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.performresumeactivity(activitythread.java:2120) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.handleresumeactivity(activitythread.java:2135) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1668) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.access$1500(activitythread.java:117) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread$h.handlemessage(activitythread.java:931) 10-23 17:27:35.763: e/androidruntime(349): @ android.os.handler.dispatchmessage(handler.java:99) 10-23 17:27:35.763: e/androidruntime(349): @ android.os.looper.loop(looper.java:123) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.main(activitythread.java:3683) 10-23 17:27:35.763: e/androidruntime(349): @ java.lang.reflect.method.invokenative(native method) 10-23 17:27:35.763: e/androidruntime(349): @ java.lang.reflect.method.invoke(method.java:507) 10-23 17:27:35.763: e/androidruntime(349): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 10-23 17:27:35.763: e/androidruntime(349): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 10-23 17:27:35.763: e/androidruntime(349): @ dalvik.system.nativestart.main(native method) 10-23 17:27:35.763: e/androidruntime(349): caused by: java.lang.nullpointerexception 10-23 17:27:35.763: e/androidruntime(349): @ com.example.blauzahn.mainactivity.cancelnotification(mainactivity.java:388) 10-23 17:27:35.763: e/androidruntime(349): @ com.example.blauzahn.mainactivity.onresume(mainactivity.java:976) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.instrumentation.callactivityonresume(instrumentation.java:1150) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activity.performresume(activity.java:3832) 10-23 17:27:35.763: e/androidruntime(349): @ android.app.activitythread.performresumeactivity(activitythread.java:2110) 10-23 17:27:35.763: e/androidruntime(349): ... 12 more
any suggestions?
mnotificationmanager
null in cancelnotification
. reinstantiate it:
protected void cancelnotification() { log.i("cancel", "notification"); mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.cancel(1); }
android android-notifications android-notification-bar
Comments
Post a Comment