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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:58:52+00:00 2026-06-15T13:58:52+00:00

I currently have a class UserFunctions that does all my user actions e.g. register,

  • 0

I currently have a class UserFunctions that does all my user actions e.g. register, login etc. In the UserFunctions class there’s a JSONParser object that does all the actual HTTP calls and returns the JSONObject.

public class UserFunctions {

    private JSONParser jsonParser;

    private static String registerURL = Constants.registerUrl;

    // constructor
    public UserFunctions(){
        jsonParser = new JSONParser();
    }

    public JSONObject register(){
        // getting JSON Object
        JSONObject json = jsonParser.getJSONFromUrl(registerURL);
        // return json
        return json;
    }
...
}

and then in my event handler of my activity classes I just do UserFunctions.register().

My question is, I now want to do all these calls in a background thread and at the same time show a ProgressDialog. I know running in the background thread is achieved with the AsyncTask.

But how should I achieve this design such that I can still do UserFunctions.register() in my Activity class, everything to be done in a background thread and a progressDialog shown.

  • 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-15T13:58:53+00:00Added an answer on June 15, 2026 at 1:58 pm

    Ok for this there are two parts the progress dialog and the async task, you need to move your JSONparser into the actual async task. If you want to use multiple progress dialogs just call them before calling the asynctask and close them when it returns

    private class JsonRetriever extends AsyncTask<Url, Void, JSONObject>{
                private JSONParser jsonParser;
                private ProgressDialog dialog;
    
        public JsonRetriever(Context c){
            dialog= new ProgressDialog(c);
            jsonParser= new JSONParser();
        }
        protected void onPreExecute() {
              dialog.setMessage("Starting retrieval");
              dialog.show();
        }
        protected JSONObject doInBackground(Url... params) {
             try{
                return jsonParser.getJSONFromUrl(params[0]);
            }catch(Exception e){
                return false;
            }
            return true;
        }
        protected void onPostExecute(final JSONObject success) {
                 if (dialog.isShowing()) {
                         dialog.dismiss();
                }
          }
    }
    

    Then to call this just do

    public JSONObject register(){
        return new JSONRetriever(this).execute(registerURL).get();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a connection class that handles all of my database connectivity. What
I currently have a class that sets the current time when an object has
I currently have a class called clientActivity that contains a finger paintig activity that
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently I have a class that is extending the ListActivity class. I need to
We currently have a utilities class that handles a lot of string formatting, date
I currently have a helper class that I am using to obfuscate a static
I currently have service classes that look something like this public class UserService :
I currently have this class that another programmer in my team coded: public static
I currently have a class that uses the KeyValuePair with List to store a

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.