android - Can't synchronize call to notify() -
forgive me, not able call on notificationbuilder's notify() method. have code:
timer.scheduleatfixedrate( new timertask() { @override public void run() { synchronized (this) { builder notif = new notificationcompat.builder(c); notif.setcontentintent(contintent) .setwhen(system.currenttimemillis()) .setticker("notification ticker") .setsmallicon(r.drawable.ic_launcher) .setcontenttitle("vinceri") .setcontenttext("ha recibido una oferta de trabajo") .setautocancel(true); notif.notify(); } } }
and no matter put synchronized block, same exception:
04-05 10:42:55.116: e/androidruntime(18244): fatal exception: timer-0 04-05 10:42:55.116: e/androidruntime(18244): java.lang.illegalmonitorstateexception: object not locked thread before notifyall() 04-05 10:42:55.116: e/androidruntime(18244): @ java.lang.object.notifyall(native method) 04-05 10:42:55.116: e/androidruntime(18244): @ com.publidirecta.vinceriazafata.notificationservice$1.run(notificationservice.java:126) 04-05 10:42:55.116: e/androidruntime(18244): @ java.util.timer$timerimpl.run(timer.java:284)
it maybe noob question but... must not receive exception? thank you.
assuming trying add notification android notification drawer.. need following:
builder notif = new notificationcompat.builder(c); notif.setcontentintent(contintent) .setwhen(system.currenttimemillis()) .setticker("notification ticker") .setsmallicon(r.drawable.ic_launcher) .setcontenttitle("vinceri") .setcontenttext("ha recibido una oferta de trabajo") .setautocancel(true); //create notification builder notification notification = notif.build(); //get instance of notificationmanager notificationmanager notificationmanager = (notificationmanager) getsystemservice(notification_service); //call notify method of notificationmanager add notification android notification drawer.. notificationmanager.notify(0, notification);
Comments
Post a Comment