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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:11:51+00:00 2026-06-01T10:11:51+00:00

For a few days a have some problem. I need to show simple ProgressBar

  • 0

For a few days a have some problem.
I need to show simple ProgressBar (not dialog) while doing some stuff in main thread…
I thought its a very simple question, but i cant do this, help me please.

First i tried simple setVisibility(View.VISIBLE) before and setVisibility(View.GONE) after.

But this is doing in the same thread, and ProgressBar freezed while my function working.

Now i have this code, but i have some error, and i dont know whats wrong..

my simple layout :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<ProgressBar
    android:id="@+id/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone" />
</FrameLayout>

i have a base activity :

public class BaseActivity extends Activity {
    public ProgressBar loading;

    public class ProgressBarShow extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... unused) {
        return(null);
    }

    protected void onProgressUpdate() {
    }
    protected void onPreExecute() {
        loading.setVisibility(View.VISIBLE);
    }

    protected void onPostExecute() {
    }
   }
}

and finally my working activity , which extends BaseActivity

public class SearchActivity extends BaseActivity {
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        loading = (ProgressBar) findViewById(R.id.loading);

        new ProgressBarShow().execute();
        //doing long stuff
        //new ProgressBarHide().execute(); there isnt, but sense the same
    }
}

I have many activities, which need progress bar, thats why i have created BaseActivity,
to not to dublicate code.

I need to do long work (stuff function) in main thread, because i want to freeze main window and not to allow user do anything (click button etc..), just show working ProgressBar.

Whats wrong in my example? Or give me some advice how can i do this better

  • 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-01T10:11:52+00:00Added an answer on June 1, 2026 at 10:11 am
    class ProgressTask extends AsyncTask<Integer, Integer, Void>{
        ProgressBar progress;
        Context context;
        public ProgressTask(ProgressBar progress, Context context) {
            this.progress = progress;
            this.context = context;
    
        }
        @Override
        protected void onPreExecute() {
            // initialize the progress bar
            // set maximum progress to 100.
            progress.setMax(100);
    
        }
    
    
        @Override
        protected Void doInBackground(Integer... params) {
            // get the initial starting value
            int start=params[0];
    
    
            // increment the progress
            for(int i=start;i<=100;i+=5){
                try {
                    boolean cancelled=isCancelled();
                    //if async task is not cancelled, update the progress
                    if(!cancelled){
                        publishProgress(i);
                        SystemClock.sleep(1000);
    
                    }
    
                } catch (Exception e) {
                    Log.e("Error", e.toString());
                }
    
            }
            return null;
        }
        //Has direct connection to UI Main thread
        //Called everytime publishProgress(int) is called in doInBackground
        @Override
        protected void onProgressUpdate(Integer... values) {
            progress.setProgress(values[0]);
            Toast.makeText(context, "test"+values[0], Toast.LENGTH_SHORT).show();
        }
    
    
        @Override
        protected void onPostExecute(Void result) {
            // async task finished
                        Log.v("Progress", "Finished");
        }
        @Override
        protected void onCancelled() {
            progress.setMax(0);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app problem that's been bugging me for a few days
I have been having this problem for the last few days and I can't
For the last few days, I have been trying to use Python for some
Have been stuck with this issue for a few days now, and really need,
I have been having some problems with this for a few days now... I
Few days ago, I came to a problem where I have to sum the
Morning, I have been working on this problem for a few days and cannot
I have a problem that has been bothering me now for a few days.
I have a problem with NSNotificationCenter. Now it crashes, but a few days ago,
For the last few days I have been attempting to find a method to

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.