Thread类中的getSystemService错误

时间:2014-07-09 18:24:34

标签: android multithreading notifications system

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();
}
}

我在getSystemService上的eclipse中遇到一个红色的x错误,说“myThread'

类型的方法getSystemService(String)未定义

HELP

1 个答案:

答案 0 :(得分:1)

此方法在Context类中定义,您无法从当前扩展Thread的类中访问它。

您必须使用context变量并执行此操作:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);