2011-10-07 125 views
0

我想創建一個通知,當用戶按下該通知並且沒有其他行爲時會自動清除。下面的通知工作正常,但是當我按下它時,它將我帶到活動「MyActivity」(即使不想使用它,甚至必須定義意圖似乎有點不必要...)如何在用戶點擊通知時取消通知?

使用FLAG_AUTO_CANCEL似乎沒有任何影響。

更新:對不起,我已經找到了FLAG_AUTO取消不工作,即通知從狀態欄清除。我想我真的想寫一個什麼都不做的意圖(或者完全刪除意圖)。

代碼...

   Notification notification = new Notification(R.drawable.success, res.getString(R.string.messages_sent), System.currentTimeMillis()); 

      //Define the expanded message and intent 
      Context context = getApplicationContext(); 
      CharSequence contentTitle = res.getString("My content title"); 


      Intent notificationIntent = new Intent(this, MyActivity.class); 
      PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
      notification.setLatestEventInfo(context, contentTitle, mStrSuccessMessage, contentIntent); 
      notification.flags |= Notification.FLAG_AUTO_CANCEL; 
      //Pass the notification to the notification manager 
      mNotificationManager.notify(1, notification); 

回答

0

在沒有實際操作的情況下使用空的意圖。

PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(), 0); 
0

我不認爲你可以。您可以立即退出MyActivity:請致電finish()onCreate()