小编Ale*_*der的帖子

Android AsyncTask冻结了UI

我正试图从服务器获取数据.尽管事实上我在doinbackground方法中完成所有连接和提取数据,但UI仍会冻结.如果有人会帮助我,我将非常感激,因为我检查了有关该主题的所有问题并且没有找到解决方案.

public class GetMessagesActivity extends AsyncTask<String, Void, String> {
    private Context context;

    private ProgressDialog progressDialog;

    public GetMessagesActivity(Context context) {

        this.context = context;
        this.progressDialog = new ProgressDialog(context);
        this.progressDialog.setCancelable(false);
        this.progressDialog.setMessage("Updating...");
        this.progressDialog.show();

    }

    protected void onPreExecute() {
    }

    @Override
    protected String doInBackground(String... arg0) {
        try {
            String pid = "1";
            String link = "somelink";
            String data = URLEncoder.encode("pid", "UTF-8") + "="
            + URLEncoder.encode(pid, "UTF-8");
            // data += "&" + URLEncoder.encode("password", "UTF-8")
            // + "=" + URLEncoder.encode(password, "UTF-8");
            URL url = new URL(link);
            URLConnection …
Run Code Online (Sandbox Code Playgroud)

user-interface android freeze android-asynctask

1
推荐指数
1
解决办法
2873
查看次数