Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:40:59+00:00 2026-06-14T08:40:59+00:00

Hello @ All out there :) I am having a little problem. I want

  • 0

Hello @ All out there 🙂
I am having a little problem. I want to show a ProgressDialog when I click on Login but nothing is shown it just does the Task without the ProgressDialog. I am using a AsyncTask and opening the ProgressDialog in that thread but nothing comes up. Here is my Source Code:

It is called like this:

ProgressDialog progress = new ProgressDialog(mainActivity);
progress.setMessage("Sie werden registriert...");

jsonParser = new JSONParser(progress, url_create_user, "POST", params);

And this is the JSONParser Class:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;

public class JSONParser extends AsyncTask<Context, Void, JSONObject>{

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    String url = "";
    String method = "";
    List<NameValuePair> parameters;
    ProgressDialog prog;

    // constructor
    public JSONParser(ProgressDialog prog, String url, String method, List<NameValuePair> param) {
        this.url = url;
        this.method = method;
        this.parameters = param;
        this.prog = prog;
    }

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0)
            {
                prog.show();
            }
            else
            {
                prog.dismiss();
            }

        }
    };

    @Override
    protected JSONObject doInBackground(Context... params) {
        try {
            handler.sendEmptyMessage(0);
            // Überprüfen welche Request Methode benutzt werden soll
            if(method == "POST"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
                        CookiePolicy.BROWSER_COMPATIBILITY);
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(this.parameters));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();

            }else if(method == "GET"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(this.parameters, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }          

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        //Stream in ein String umwandeln
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Fehler!", "Fehler mein umwandeln von Stream in String: " + e.toString());
        }

        // JSON Object parsen
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error beim parsen " + e.toString());
        }
        handler.sendEmptyMessage(1);
        // Das JSONObject zurückgeben
        return jObj;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:41:00+00:00Added an answer on June 14, 2026 at 8:41 am
    see the following example code of JSON parser with async task
    
    package com.androidhive.jsonparsing;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.UnsupportedEncodingException;
    import java.util.ArrayList;
    import java.util.HashMap;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    import android.app.ListActivity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
    
    public class AndroidJSONParsingActivity extends ListActivity {
    
        // url to make request
        private static String url = "http://api.androidhive.info/contacts/";
    
        // JSON Node names
        private static final String TAG_CONTACTS = "contacts";
        private static final String TAG_ID = "id";
        private static final String TAG_NAME = "name";
        private static final String TAG_EMAIL = "email";
        private static final String TAG_ADDRESS = "address";
        private static final String TAG_GENDER = "gender";
        private static final String TAG_PHONE = "phone";
        private static final String TAG_PHONE_MOBILE = "mobile";
        private static final String TAG_PHONE_HOME = "home";
        private static final String TAG_PHONE_OFFICE = "office";
        static InputStream is = null;
        static JSONObject jObj = null;
        static String json = "";
    
        // contacts JSONArray
        JSONArray contacts = null;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            new GetEventsTask().execute("");
        }
    
        protected class GetEventsTask extends
                AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {
            protected ArrayList<HashMap<String, String>> contactList;
    
            private final ProgressDialog dialog = new ProgressDialog(
                    AndroidJSONParsingActivity.this);
    
            //PreExecute Method
    
            protected void onPreExecute() {
                this.dialog.setMessage("Loading, Please Wait..");
                this.dialog.setCancelable(false);
                this.dialog.show();
            }
    
            //doInBackground Method
    
            @Override
            protected ArrayList<HashMap<String, String>> doInBackground(
                    String... params) {
                contactList = new ArrayList<HashMap<String, String>>();
                // Making HTTP request
                try {
                    // defaultHttpClient
                    DefaultHttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost(url);
    
                    HttpResponse httpResponse = httpClient.execute(httpPost);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    is = httpEntity.getContent();
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(is, "iso-8859-1"), 8);
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                    }
                    is.close();
                    json = sb.toString();
    
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
                // try parse the string to a JSON object
                try {
                    jObj = new JSONObject(json);
                    Log.i("json objects",""+json);
                } catch (JSONException e) {
                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                }
                try {
                    // Getting Array of Contacts
                    contacts = jObj.getJSONArray(TAG_CONTACTS);
    
                    // looping through All Contacts
                    for (int i = 0; i < contacts.length(); i++) {
                        JSONObject c = contacts.getJSONObject(i);
    
                        // Storing each json item in variable
                        String id = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);
                        String email = c.getString(TAG_EMAIL);
                        String address = c.getString(TAG_ADDRESS);
                        String gender = c.getString(TAG_GENDER);
    
                        // Phone number is agin JSON Object
                        JSONObject phone = c.getJSONObject(TAG_PHONE);
                        String mobile = phone.getString(TAG_PHONE_MOBILE);
                        String home = phone.getString(TAG_PHONE_HOME);
                        String office = phone.getString(TAG_PHONE_OFFICE);
    
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();
    
                        // adding each child node to HashMap key => value
                        map.put(TAG_ID, id);
                        map.put(TAG_NAME, name);
                        map.put(TAG_EMAIL, email);
                        map.put(TAG_PHONE_MOBILE, mobile);
    
                        // adding HashList to ArrayList
                        contactList.add(map);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
    
                return contactList;
            }
    
            //onPostExecute Method 
    
    
            protected void onPostExecute(ArrayList<HashMap<String, String>> result) {
    
                ListAdapter adapter = new SimpleAdapter(getApplicationContext(),
                        contactList, R.layout.list_item, new String[] { TAG_NAME,
                                TAG_EMAIL, TAG_PHONE_MOBILE }, new int[] {
                                R.id.name, R.id.email, R.id.mobile });
                // selecting single ListView item
                ListView lv = getListView();
                lv.setAdapter(adapter);
    
    
    
                // Launching new screen on Selecting Single ListItem
                lv.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                        // getting values from selected ListItem
                        String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                        String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
                        String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();
    
                        // Starting new intent
                        Intent in = new Intent(getApplicationContext(),SingleMenuItemActivity.class);
                        in.putExtra(TAG_NAME, name);
                        in.putExtra(TAG_EMAIL, cost);
                        in.putExtra(TAG_PHONE_MOBILE, description);
                        startActivity(in);
                    }
                });
                if (this.dialog.isShowing()) {
                    this.dialog.dismiss();
                }
            }
    
        }
    
    }
    

    Let me know your problem is resolved or not?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello all you math whizzes out there! I am struggling with a math problem
Hello to all, Double d = 1.000000000000000000000000000000001; System.out.println(d); The code above prints 1.0 but
Hello to all you people out there I have been trying to download the
Hello all you helpful people out there (and goodbye none-helpful people :D ). I'm
Hello all I am working on javascript jquery and svg.I want to ask a
hello all this seems to be my problem I have a table in mysql
Hello all I am working in javascript and html5.I want to ask that how
Problem Hello all! I have this code which takes my jpg image loops through
Hello ladies and gents, I'm having a bit of problem with accept() . I
Hello Every Developer out there...!!!! I m currently using Phonegap 1.4.0 on iphone and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.