Myactivity
包含一个 inner private class
,这基本上就是它的样子,但有问题:
public class MyActivity extends Activity
{
// My xmlData that I want to fill in the asynchronous task
XMLData xmlData;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
GetXMLTask task = new GetXMLTask(this);
task.execute(url);
if(xmlData == null) System.out.print("problem");
// Prints "problem" : my xmlData is null, why?
}
private class GetXMLTask extends AsyncTask<String, Void, Void>
{
public GetXMLTask(Activity context)
{
// Constructor
}
protected Void doInBackground(String... params)
{
// Here some stuff to get and parse my XML
xmlData = new XMLData(list);
System.out.print(xmlData.list.size());
// this line shows that I correctly fill my xmlData object
}
}
}
问题是在调用内部异步类之后,我的 xmlData 值为 null,我不知道为什么。我也在我的GetXMLTask
:
MyActivity.this.xmlData = new XMLData(list);
还是不行,为什么呢?我究竟做错了什么?谢谢你的帮助。