哪个进程更好地在android中显示加载页面?

时间:2016-05-16 19:16:10

标签: android android-asynctask httpconnection

我需要一个加载过程等待http响应查询到我的服务器,哪种方法更好解决它?

我尝试使用AsyncTask但效果不佳,我恢复数据的过程是:首先我制作HttpsURLConnection并解析所有xml文件,然后将其保存在List中,此过程可以等待5-10秒。 ..我不知道这个过程在doInBackground()中是否正确

这是我的代码,但AsyncTask状态始终是RUNNING ..

由于

class GetTask extends AsyncTask<String, Void, Integer> {
Context context;
private ApiConnection xml_parse = new ApiConnection();
ProgressDialog  mDialog;
private List<Orders> orders;

public GetTask (Context context){
    this.context = context;
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
    mDialog = new ProgressDialog(context);
    mDialog.setMessage("Cargando datos...");
    mDialog.show();
}

@Override

protected Integer doInBackground(String... params) {
    int count = params.length;
     orders = new ArrayList<Orders>();
    for (int i = 0; i < count; i++) {

        try {
            orders = xml_parse.tester_orders(params[0]);

        } catch (Exception e) {
            e.printStackTrace();
        }
        // Escape early if cancel() is called
        if (isCancelled()) break;
    }
    return count;
}

protected void onPostExecute(Integer result) {
    mDialog.dismiss();
}

public List<Orders> getOrders(){
    return orders;
}

活动

String order_url = "myurlquery";
   GetTask XX = new GetTask(this);
    XX.execute(order_url);
...
if(XX.getStatus().toString() =="FINISHED") {
List<Order> orders = XX.getOrders();
//Print List to ListvView..
}

0 个答案:

没有答案