0

因此,我正在嘗試使用NotificationHelper來通知用戶下載的進度。可能創建兩個NotificationHelper實例?

public class MapDownload extends AsyncTask<String, Integer, String>{ 
    public MapDownload(ArrayList<PlaceDetails> placeList, int travelogueID, Context mContext, String travelogueName){ 
     this.places = placeList; 
     this.zoom = 12; 
     this.tID = travelogueID; 
     mNotificationHelper = new NotificationHelper(mContext, travelogueName); 
    } 

    @Override 
    protected void onPreExecute(){ 
     //Create the notification in the statusbar 
     mNotificationHelper.createNotification(); 
    } 
} 

不過,我想知道是否有可能實現它這樣的,如果我發動另一MapDownload類下載的東西,我怎麼能做到這一點,從而將兩者同時運行的?看來第二個MapDownload發射時,第一個消失,而第二個消息將替換先前的通知。

這是一個錯誤的AsyncTask執行的問題,或錯誤的使用方法NotificationHelper

回答

0

我不知道NotificationHelper是什麼,它來自第三方庫嗎?

但是,創建通知時,您必須提供一個ID。如果稍後重複使用相同的ID,則先前的通知將被替換。請參閱NotificationManger文檔。

也許這是發生了什麼。

+0

嗯,我不確定,我按照從這裏的指南:http://eliasbland.wordpress.com/2011/03/11/an-example-of-how-to-run-a-background-task -and-report-progress-in-the-status-bar-using-asynctask-on-android /#comment-285 ... NotificationManager會是一個更簡單的解決方案嗎? – lyk 2013-02-11 14:23:23

+0

好的,我看到你來自哪裏,關於ID! – lyk 2013-02-11 14:24:56

+0

您可以使用Google兼容庫提供的'NotificationCompat.Builder'。這很容易使用:[創建一個簡單的通知](http://developer.android.com/guide/topics/ui/notifiers/notifications.html#SimpleNotification) – nicopico 2013-02-11 14:43:47