java - NotificationManager: cancel(id) DON'T work -
from service, show notification. have code:
public final static int notification = 1; public final static int notification2 = 2; case notification2: builder.setsmallicon(r.drawable.ic_action_about); builder.setcontenttitle(context.getstring(r.string.app_name)); new thread(new runnable() { @override public void run() { // todo auto-generated method stub for(int i=0;i<10;i++) { builder.setcontentinfo(i+"/"+10); notificationmanager.notify(notification2, builder.build()); try { thread.sleep(1000); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } } } }).start(); notificationmanager.cancel(notification2); break;
the code works fine, when thread finished notification remain. why? want cancel , cancel()
doesn't work.
because start asynchronous thread displays notification, notificationmanager.cancel(notification2);
called immediately. means notification not displayed yet, when cancelled it.
try move notificationmanager.cancel(notification2);
run() method.
Comments
Post a Comment