我正在尝试在名为 Opciones 的类的 AsyncTask 中获取上下文(该类是唯一调用该任务的类),但我不知道该怎么做,我看到了一些这样的代码:
protected void onPostExecute(Long result) {
Toast.makeText(Opciones.this,"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: ", Toast.LENGTH_LONG).show();
}
但它对我不起作用,它说:“范围内没有 Opciones 类型的封闭实例”
最佳答案
你需要做以下事情。
例子
public class MyCustomTask extends AsyncTask<Void, Void, Long> {
private Context mContext;
public MyCustomTask (Context context){
mContext = context;
}
//other methods like onPreExecute etc.
protected void onPostExecute(Long result) {
Toast.makeText(mContext,"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: ", Toast.LENGTH_LONG).show();
}
}
并通过以下方式实例化类。
MyCustomTask task = new MyCustomTask(context);
task.execute(..);
https://stackoverflow.com/questions/16920942/
相关文章:
android - 如何使用 Android Studio 查看共享首选项文件?
android - Android PopupWindow Activity 时背景模糊或变暗
android - 如何在没有硬件加速的情况下在 Windows 8 上为 API 21 和 19
android - 什么是 CSS 的 dp(密度独立像素)单位?
android - NoSuchFieldError : No static field listV
android - 何时清除 Android 中的缓存目录?
android - 如何将 Activity 带到前台(堆栈顶部)?
android - transformClassesAndResourcesWithProguard