2013-02-07 54 views
1

我使用NotificationCompat.Builder創建了通知對象,然後在我的服務中的其他地方我想更新value。什麼是正確的方法來做到這一點?我應該取消這個對象,並建立另一個?編輯通知對象?

Intent intent = new Intent(this, MainActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); 

    Notification noti = new NotificationCompat.Builder(this) 
    .setContentTitle("App") 
    .setContentText("estimated value:" + String.valueOf(value)) // <---- wanna update this 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setContentIntent(pendIntent) 
    .build(); 

    startForeground(1235, noti); 

回答

1

您不需要取消先前的通知。相反,您可以簡單地使用不同的內容文本運行相同的代碼(在這種情況下,更改value)。

欲瞭解更多信息,請參閱Android文檔的Updating Notifications部分。

+0

謝謝,'NotificationManager'正是我一直在尋找的東西。我不知道爲什麼我找不到我自己:) – Kristopher