我有一个服务,并在该服务中我有一个线程。该线程有一个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