你好,我想使用异步任务,这是我的sceleton代码:异步任务2个功能doInBackground
public class MyActivity extends Activity {
private ProgressDialog pd = null;
private Object data = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Show the ProgressDialog on this thread
this.pd = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);
// Start a new thread that will download all the data
new DownloadTask().execute("Any parameters my download task needs here");
}
private class DownloadTask extends AsyncTask<String, Void, Object> {
protected Object doInBackground(String... args) {
Log.i("MyApp", "Background thread starting");
// This is where you would do all the work of downloading your data
return "replace this with your data object";
}
protected void onPostExecute(Object result) {
// Pass the result data back to the main activity
MyActivity.this.data = result;
if (MyActivity.this.pd != null) {
MyActivity.this.pd.dismiss();
}
}
}
我的问题是什么应该是在的AsyncTask的第三个参数如果我将做InBackground函数返回一个字符串数组和一个位图?任何帮助?
我不知道这是不是最好的办法来解决这个问题,但无论如何它应该工作。 – Fishbreath 2012-03-14 19:16:00
以及如何访问字符串结果?如果我的temp是DownloadTaskResult,我可以写temp.stringResult吗? – 2012-03-14 22:48:59
是的。这就是说,Torid的答案是一个更一般的解决方案,如果更复杂的话。 – Fishbreath 2012-03-15 02:41:16