在AsyncTask上的getApplication()上找不到符号

Vit*_*sky 1 android android-asynctask

我正在使用AsyncTask并希望使用getApplication()来处理类Application.但getApplication()获取错误无法找到符号.

我的代码:

public class  splash extends AsyncTask {
  protected config app;
  public  splash(Context context) {
  super();
  app = ((config) getApplication());
  this.context=context;
}
Run Code Online (Sandbox Code Playgroud)

和我想要使用的类:

public class config extends Application
{
  public Boolean  con=true;
  public int status=-1;
  public String actNum; 
  public void onCreate()
  {
    super.onCreate();
  }
}
Run Code Online (Sandbox Code Playgroud)

Dir*_*kel 7

如果要获取Application实例,可以onCreate()使用它初始化成员并通过类方法返回它:

public class ApplicationConfig extends Application {

  private static ApplicationConfig instance;

  public void onCreate() {
    super.onCreate();
    instance = this;
  }

  public static ApplicationConfig getConfig() {
    return instance;
  }
}
Run Code Online (Sandbox Code Playgroud)

然后您可以通过以下方式检索此实例:

ApplicationConfig conf = ApplicationConfig.getConfig();
Run Code Online (Sandbox Code Playgroud)