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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:18:25+00:00 2026-05-21T07:18:25+00:00

Is it possible to change PD’s style, message and title on the fly (and

  • 0

Is it possible to change PD’s style, message and title on the fly (and not from UI thread)?

I want to do the following. Fist time PD shows in STYLE_SPINNER as it looks like endless progress and shows the message informing user that app is looking 4 something (some update 4 instance). And when it found that something it has to do something with it (install it). At this point i wanna show the HORIZONTAL styled PD as it really shows the progress state instead of spinner styled one.

Anyway I got NullPointerException while trying to PD.setMax(). PD isn’t null so I can’t get what’s going on.

This is an inner class in my Activity class:

    private class RestoreDBTask extends AsyncTask <Void, Void, String>
    {

        private ProgressDialog dialog;

        private Handler handler;

        @Override
        protected void onPreExecute()
        {

            this.dialog = new ProgressDialog(SplashActivity.this);
            this.dialog.setTitle(getString(R.string.progress_wait));
            this.dialog.requestWindowFeature(Window.FEATURE_PROGRESS);
//            this.dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            this.dialog.setProgress(0);
            this.dialog.show();

            handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    RestoreDBTask.this.dialog.hide();

                    switch (msg.what) {
                    case 0:{
                        RestoreDBTask.this.dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        break; }
                    case 1: {
                        RestoreDBTask.this.dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        break; }
                    case -1: {
                        RestoreDBTask.this.dialog.setMessage(getResources().getString(R.string.progress_db_installing));
                        break; }
                    case -2: {
                        RestoreDBTask.this.dialog.incrementProgressBy(1);
                        break; }
                    default: {
                        Log.i(APP_TAG,""+RestoreDBTask.this.dialog.getMax());
                        RestoreDBTask.this.dialog.setMax(msg.what); }
                    }

                    RestoreDBTask.this.dialog.show();
                }
            };
        }

        @Override
        protected String doInBackground(Void... params)
        {
            mDBHelper.initDB(dialog,handler);
            return "";
        }

        @Override
        protected void onPostExecute(String result)
        {
            dialog.dismiss();
            startNextActivity();
        }
    }

the mDBHelper.initDB() method uses handler.sendEmptyMessage() calls with some int values assuming if msg.what>1 it is Max value for PD.
Also I can’t figure out why PD doesn’t show the progress state if it’s style is STYLE_SPINNER? If i change it to STYLE_HORIZONTAL it works ok…

  • 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-21T07:18:26+00:00Added an answer on May 21, 2026 at 7:18 am

    Is it possible to change PD’s style, message and title on the fly (and not from UI thread)?

    It’s not possible to update UI stuff in another Thread. What you should do is to override onProgressUpdate() and there you can update the UI while the code in doInBackground() still processing.

    Sample code:

    @Override
    protected String doInBackground(Void... params) {
    
        // Use publishProgress() to update the UI thread from
        // a working background process.
    
        // If you have the initDB in another class you should probably
        // pass your RestoreDBTask instance to your initDB and call the instance's
        // makeProgress() method to successfully use publishProgress().
        mDBHelper.initDB(dialog, handler, this);
        return "";
    }
    
    @Override
    protected void onProgressUpdate(Integer... params) {
        // If you gradually should update the ProgressDialog you probably need
        // an Integer value as argument in this method.
    
        // Update the ProgressDialog here.
    }
    
    public void makeProgress(Integer... params) {
        publishProgress(params);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to change the resolution time calculation to start not with the
Is it possible to change the frame title when using \againframe from the Beamer
Possible Duplicate: Change icon on of an App in iOS 4 in run-time Is
Is it possible to change C#'s built-in Vector3 struct to not use floating point
Is it possible to change object's value not directly? For example a = {x:
Is it possible to change the size of an UITabBarItem? I'm not talking about
Is it possible to change property value from xaml? Imagine we have a usercontrol
Is it possible to change the ObjectId field name from '_id' to 'id', or
Possible Duplicate: Change the native confirm/alert alert(hello) Is there anyway to change the style
Is it possible to change the style of a class via JavaScript without looping

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.