是的,还有另一个选项.. Internet 连接和数据库连接应该在 AyncTask 或 Handler 中进行。这将缩短连接时间(连接将在后台进行)..
这是异步任务的示例:
private class YourTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... s) {
//Here you have to make the loading / parsing tasks
//Don't call any UI actions here. For example a Toast.show() this will couse Exceptions
// UI stuff you have to make in onPostExecute method
}
@Override
protected void onPreExecute() {
// This method will called during doInBackground is in process
// Here you can for example show a ProgressDialog
}
@Override
protected void onPostExecute(Long result) {
// onPostExecute is called when doInBackground finished
// Here you can for example fill your Listview with the content loaded in doInBackground method
}
}
要执行 AsyncTask:
新的 YourTask().execute("");