Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressDialog not showing while making HTTP request

I want to show ProgressDialog when http connection request.

there is request method.

protected Result request(String urlStr, String postData) {
    ProgressDialog dialog = ProgressDialog.show(activity, "", "Loading...",true);
    Result result = new Result();
    String message = "";
    try {
        message = HttpRequest.postURL(urlStr, postData);
        result = new Result(message);
    } catch (Exception e) {
        Log.e(TAG,"Failed to request data from " + urlStr + "\n" + e.getMessage());
    }
    dialog.dismiss();
    return result;
}

but when this method running. the ProgressDialog not showing. how to solve this problem?

like image 587
Joe Avatar asked Sep 21 '26 23:09

Joe


1 Answers

You need to call dialog.show()

Start the dialog and display it on screen. The window is placed in the application layer and opaque. Note that you should not override this method to do initialization when the dialog is shown, instead implement that in onStart().

Also, what I do suggest is that you do this in AsyncTask class' doInBackground().
In the onPreExecute(), display the ProgressDialog and in the onPostExecute() dismiss it.

like image 172
An SO User Avatar answered Sep 23 '26 13:09

An SO User