我有这个代码用于管理数据库中的某些国家/地区;
class checkCountryAsync extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
setContentView(R.layout.main);
}
@Override
protected String doInBackground(String... aurl) {
MDPIActivity.this.runOnUiThread(new Runnable() {
public void run() {
CountryTable country = new CountryTable() ;
country.EnterCountry();
}
});
return null;
}
}
这样,我想设置内容 View ,然后在后台设置 onBackground 方法的工作原理,但我仍然需要等待内容 View ,直到 onBackground 方法未完成。
谢谢。
最佳答案
我看不出有任何理由将 setContentView()
放在 onPreExecute
方法中,它应该放在 onCreate
方法中当您尝试查找 View 时,避免任何类型的 NullPointerException
,对于您的 AsyncTask
,您应该只使用 onPostExecute()
这是在方法 doInBackground()
关于android - AsyncTask 和 setContentView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9360199/