【发布时间】:2020-04-09 13:39:31
【问题描述】:
我想在 MainActivity 创建的 AsyncTask 在后台运行时检查 MainActivity 中的变量,然后在此变量设置为某个值时结束 AsyncTask,假设为 true;
主活动
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
new MyTask(this).execute();
}
我的任务
public class MyTask extends AsyncTask<Void, Void, Void>
{
@Override
protected Void doInBackground(Void... ignore)
{
//check for MainActivity variable then exit or PostExecute when this variable is set to true?
}
}
【问题讨论】:
-
这能回答你的问题吗? Ideal way to cancel an executing AsyncTask
-
几乎,但我的运行变量将从我的 MainActivity 中评估。我该怎么做?
标签: java android android-asynctask