首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置timed ProgressDialog?

如何设置timed ProgressDialog?
EN

Stack Overflow用户
提问于 2013-06-26 15:50:28
回答 1查看 81关注 0票数 0

我有这样的代码:类AttemptLogin扩展AsyncTask {

代码语言:javascript
复制
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MyAkan.this);
        pDialog.setMessage("Attempting login...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... arg0) {
        int success;
        String idnumber = etIdnumber.getText().toString();
        String password = etPassword.getText().toString();

        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("idnumber", idnumber));
            params.add(new BasicNameValuePair("password", password));

            JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
                    params);

            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Login Successful!", json.toString());

                Intent i = new Intent("com.gpplsmje.mac.akan.AKANMENU");
                String id = json.getString(TAG_IDNUMBER);
                i.putExtra("idnumber", id);
                finish();
                startActivity(i);
                return json.getString(TAG_MESSAGE);
            } else if (success == 0) {
                Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String file_url) {
        // TODO Auto-generated method stub
        pDialog.dismiss();
        if (file_url != null) {
            Toast.makeText(MyAkan.this, file_url, Toast.LENGTH_LONG).show();
        }
    }

}

此应用程序连接到服务器并返回编码的JSON数据。每当我在我的机器上的本地服务器上测试它时,它都工作得很好。它与服务器连接得很好。但当我关闭服务器并使用应用程序时,应用程序加载,但在尝试登录一分钟左右后停止。有没有一种方法可以将进度计时到最多20秒,然后如果它消耗了时间,它必须取消进度对话框并返回到主要活动?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-26 16:19:22

你的jsonParser对象使用HTTPURLConnection来做http请求吗?如果是这样的话,就有一个setConnectTimeout方法。

如果您正在使用DefaultHttpClient,请查看此问题How to set HttpResponse timeout for Android in Java

请记住,在Android2.2上,最好使用HTTPURLConnection。有关更多细节,请查看http://android-developers.blogspot.fr/2011/09/androids-http-clients.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17314446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档