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