Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 线程类内的getSystemService错误_Android_Multithreading_Notifications_System - Fatal编程技术网

Android 线程类内的getSystemService错误

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

我在eclipse的getSystemService上收到一个红色的x错误,表示“myThread类型的方法getSystemService(String)未定义”


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