gpt4 book ai didi

android - AsyncTask 和 setContentView

转载 作者:行者123 更新时间:2023-11-29 00:40:57 26 4
gpt4 key购买 nike

我的数据库中有用于管理某些国家/地区的代码;

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com