我有一個服務,並在該服務中我有一個線程。該線程有一個Runnable。從runnable我嘗試發佈通知,但我得到這個錯誤。從服務中連續運行的線程發佈通知
The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) in the type Notification is not applicable for the arguments (new Runnable(){}, CharSequence, CharSequence, PendingIntent)
如果我嘗試從外部線程發佈,一切工作正常。 我的應用程序不斷從服務器獲取響應。當有來自服務器的更新數據並且應用程序未運行時,會創建新的通知。爲了避免在主線程上運行,我創建了一個新線程。
另一種方式來引用類實例'this'內'Runnable'是使用類名:'MyService.this'。這樣你就不必費心使用一個變量。 – Joffrey