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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:02:44+00:00 2026-06-07T14:02:44+00:00

I have an Activity which downloads the data from the Database. While the Activity

  • 0

I have an Activity which downloads the data from the Database. While the Activity is doing this work, I want to show the progress with ProgressDialog.I use ProgressDialog.STYLE_HORIZONTAL because I want to show the actual values. I use a Handler to start the Activity which displays the ProgressDialog:

Intent intent = new Intent(this, ProgressDialogActivity.class);

private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what == SET_PROGRESS){


                intent.putExtra("action", "show");
                intent.putExtra("progress", msg.arg1);
                intent.putExtra("max", msg.arg2);
                intent.putExtra("message", syncMessage);
                intent.putExtra("title", R.string.please_wait);

                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);
            }
            else if(msg.what == SHOW_PROGRESS){             


                intent.putExtra("action", "show");
                intent.putExtra("title", syncMessage);

                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);              
            }
            else if(msg.what == HIDE_PROGRESS){


                intent.putExtra("action", "hide");
                intent.putExtra("message", "");
                intent.putExtra("title", "");

                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                startActivity(intent);

            }
        }
    };

Here is the ProgressDialogActivity:

    public class ScreenProgressDialog extends Activity {

    ProgressDialog pd;
    Bundle extras;
    String action;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        extras = getIntent().getExtras();
        pd = new ProgressDialog(this);

        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setCancelable(false);

        pd.setProgress(extras.getInt("progress"));  
        pd.setMax(extras.getInt("max"));
        pd.setMessage(extras.getCharSequence("message"));
        pd.setTitle(extras.getString("title"));

        action = extras.getString("action");

        if (action.equals("show")){
            pd.show();                  
        }
        else{
            pd.dismiss();
        }

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

}

When the Main Activity downloads a new table from the Database the Handler starts a new ProgressDialogActivity and a new Activity appears. I would like to avoid this. My aim is to show only ONE Activity which displays the ProgressDialog with the correct values.
(I cannot create a ProgressDialog in the Main Activity, I have to find another way. It’s some kind of homework but I need some help).
Thank you!

  • 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-07T14:02:46+00:00Added an answer on June 7, 2026 at 2:02 pm

    You can use AsyncTask to fetch data in background and show ProgressDialog
    Here is code:

    // Get feed!
    new ProgressTask().execute();
    
    
    
    private class ProgressTask extends AsyncTask<String, Void, Boolean> {
    
        private ProgressDialog dialog = new ProgressDialog(HomeActivity.this);
    
        /** progress dialog to show user that the backup is processing. */
        /** application context. */
    
        protected void onPreExecute() {
            this.dialog.setMessage("Please wait");
            this.dialog.show();
        }
    
        protected Boolean doInBackground(final String... args) {
            try {
    
                /**
                 * Fetch the RSS Feeds from URL
                 */
                Utilities.arrayRSS = objRSSFeed
                        .FetchRSSFeeds(Constants.Feed_URL);
                return true;
            } catch (Exception e) {
                Log.e("tag", "error", e);
                return false;
            }
        }
    
        @Override
        protected void onPostExecute(final Boolean success) {
    
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
    
            if (success) {
                // display UI
                UpdateDisplay();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one activity which download data from the web. In middle of the
I have an activity which shows 3 random images from JSON data off the
I have an Activity which uses a Fragment . I simply want to pass
I have a Service downloading data every second from a web server (This Service
this is the current state/situation: I have an Activity which binds a Service which
I have an activity which downloads images in background in a listView using AsyncTask,
I have to an Activity in which I have to update the progress of
I have an activity which shows an image (ViewCollection.java). I want to only create
I have an Activity which I want to be finished when user rotates the
i have a service which fetches some data from network.i am sending data download

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.