Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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 AsyncTask doInBackground参数与构造函数参数_Android - Fatal编程技术网

Android AsyncTask doInBackground参数与构造函数参数

Android AsyncTask doInBackground参数与构造函数参数,android,Android,在doInBackground中,我需要引用应用程序上下文或活动 newmyasynctask(getApplicationContext())和doInBackground(Context…params)在线程安全和其他可能的多线程概念、限制方面有什么区别吗 谢谢。没有。假设您有: private class MyAsyncTask extends AsyncTask<Context, Integer, Long> { private Context _context = nu

在doInBackground中,我需要引用应用程序上下文或活动

newmyasynctask(getApplicationContext())
doInBackground(Context…params)
在线程安全和其他可能的多线程概念、限制方面有什么区别吗


谢谢。

没有。假设您有:

private class MyAsyncTask extends AsyncTask<Context, Integer, Long> {
  private Context _context = null;

  MyAsyncTask(Context context) {
    _context = context;
  }

  protected Long doInBackground(Context... context) {
     // if _context and context are the same, it doesn't matter
     // which you use.
     return 0;
  }

  protected void onProgressUpdate(Integer... progress) {
    // update progress
  }

  protected void onPostExecute(Long result) {
    // publish result
  }
}
请参阅
Context useMe = getApplicationContext();
MyAsyncTask task = new MyAsyncTask(useMe);
task.execute(useMe); // should use this if provided, otherwise, what was in constructor