Android 线程类内的getSystemService错误
我在eclipse的getSystemService上收到一个红色的x错误,表示“myThread类型的方法getSystemService(String)未定义”Android 线程类内的getSystemService错误,android,multithreading,notifications,system,Android,Multithreading,Notifications,System,我在eclipse的getSystemService上收到一个红色的x错误,表示“myThread类型的方法getSystemService(String)未定义” HELP此方法在上下文中定义,您无法从扩展线程的当前类访问它 您必须使用上下文变量并执行以下操作: public class myThread extends Thread { Context context; public myThread (Context c) { this.context = c; } @Over
HELP此方法在
上下文中定义,您无法从扩展线程的当前类访问它
您必须使用上下文
变量并执行以下操作:
public class myThread extends Thread
{
Context context;
public myThread (Context c)
{
this.context = c;
}
@Override
public void run()
{
super.run();
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);