1
我在我的服務中收到了一條通知,我在我的onDestroy中取消了該通知。立即在取消代碼執行後重新顯示通知。任何線索?我試過所有的旗幟組合。沒有快樂。爲簡潔起見編輯的代碼在這裏。取消後通知重新出現
public class downservice extends Service{
Notification notification;
RemoteViews contentView;
private static final int notifyid = 1;
Context context;
NotificationManager mNM;
PendingIntent cintent;
@Override
public void onCreate() {
String ns = Context.NOTIFICATION_SERVICE;
mNM = (NotificationManager)getSystemService(ns);
Intent noteintent = new Intent(this, configact.class);
cintent = PendingIntent.getActivity(this, 0, noteintent, 0);
contentView= new RemoteViews(getPackageName(), R.layout.notify);
Message msgtx=Message.obtain();
handler.sendMessage(msgtx);
}
private void showNotification(long[] data) {
notification= new Notification();
notification.contentIntent = cintent;
notification.icon=R.drawable.notify;
notification.iconLevel=x;
notification.flags|=Notification.FLAG_AUTO_CANCEL;
contentView.setImageViewResource(R.id.notifyimage, R.drawable.notifyimage);
contentView.setTextViewText(R.id.notifytext,text);
notification.contentView = contentView;
// We use a layout id because it is a unique number. We use it later to cancel.
mNM.notify(notifyid, notification);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public void onDestroy() {
mNM.cancel(notifyid);
}
private Handler handler=new Handler(){
@Override
public void handleMessage(Message msg){
Message msgtx=Message.obtain();
msgtx.arg1=1;
long [] data=getdata();
showNotification(data);
handler.sendMessageDelayed(msgtx, updaterate*1000);
}
};
你能分享你的代碼的相關部分嗎?通知何時創建以及何時取消? – 2011-02-24 12:34:49