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 6342697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:17:27+00:00 2026-05-24T20:17:27+00:00

I am trying to get data from a webserver and display a message saying

  • 0

I am trying to get data from a webserver and display a message saying “ok” or “invalid key”. While it is getting the data it should produce a progress dialog. I have tried many methods including putting it inside of a thread however inside a thread the alert dialogs won’t work. I have tried to use the async task method but it doesnt seem to work either. Can someone help me find a solution? Thanks

verifyCode.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
    //I surround the async task with the progressdialog so that it should show while the method is working in the background
        final ProgressDialog progressDialog = ProgressDialog.show(
                    Activate.this, "", "Loading...");
            new checkActivationCode().execute(activationCode.toString().toUpperCase()
                    );

            progressDialog.dismiss();       
        }
    });

   public class checkActivationCode extends AsyncTask<String, Void, Void> {

    @Override
    protected Void doInBackground(String... activationCode) {
        // TODO Auto-generated method stub
        try {
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpPost httpost = new HttpPost(
                    "https://iphone-radar.com/accounts/confirmation");

            JSONObject holder = new JSONObject();

            holder.put("code", activationCode);
            StringEntity se = new StringEntity(holder.toString());
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            ResponseHandler responseHandler = new BasicResponseHandler();
            String response = httpclient.execute(httpost, responseHandler);

            if (response != null) {
                org.json.JSONObject obj = new org.json.JSONObject(response);

                if ("00000000-0000-0000-0000-000000000000".equals(obj
                        .getString("id"))) {
                    new AlertDialog.Builder(Activate.this)
                            .setTitle(
                                    getResources().getString(
                                            R.string.InvalidKey))
                            .setMessage(
                                    getResources()
                                            .getString(
                                                    R.string.PleaseEntervalidRegistration))
                            .setNeutralButton("OK", null).show();

                } else {
                    // add permanent variables
                    SharedPreferences prefs = getSharedPreferences(
                            "Settings", 0);
                    SharedPreferences.Editor editor = prefs.edit();

                    editor.putBoolean("ACTIVATED", true);
                    editor.putString("ID", obj.getString("id"));
                    editor.commit();

                    Intent imTracking = new Intent(Activate.this,
                            ImTracking.class);
                    imTracking.putExtra("ActivationSuccessful", true);
                    // transfer more data
                    startActivity(imTracking);
                }
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        return null;
    }

}
  • 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-05-24T20:17:29+00:00Added an answer on May 24, 2026 at 8:17 pm

    You can’t show any kind of dialog or progress dialog from the doInBackground() method because it doesn’t run on the UI Thread. You will want to update the UI with progress updates using the onProgressUpdate() method. If you want to show an AlertDialog on completion, use the onPostExecute() method. Both onProgressUpdate() and onPostExecute() run on the UI thread, so your AlertDialog code will work properly.

    Here’s the AsyncTask page with some sample code on how to properly use it (including where to provide updates to the UI): http://developer.android.com/reference/android/os/AsyncTask.html

    Here’s some SO questions covering the same topic: How to use AsyncTask to show a ProgressDialog while doing background work in Android?

    Updating progress dialog in Activity from AsyncTask

    How can I remove an alert dialog after a AsyncTask has done it's work

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

Sidebar

Related Questions

i am trying to get data from db, but in while loop, first data
What is the best way of handling trying to get data from a DataReader
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
for example I'm trying to get the data from database like: using (ExplorerDataContext context
I have sugar crm instance and i was trying to get some data from
I'm trying to get the video data from this youtube playlist feed and add
I am trying to get some form data from POST method. Here's the code
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint
I am trying to rewrite an url with GET-data from a form. This works
Im trying to get a completly data copy from a gridview, itryed clone(), tryed

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.