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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:20:38+00:00 2026-06-04T05:20:38+00:00

I need to show a second activity after the progress bar is filled. I

  • 0

I need to show a second activity after the progress bar is filled. I tried the code below but it doesn’t show the progress bar and just shows my second activity.

This is the code:

   public class MiSuper2 extends Activity {
        String strListas[] = null;
        private ProgressBar mProgress;
        private int mProgressStatus = 0;
        private Handler mHandler = new Handler();
        private StoreData stdArticulos = null;
        public Cursor cursor = null;
        private long fileSize = 0;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        stdArticulos = new StoreData(this);

        fileSize = 0;
        setContentView(R.layout.main);
        stdArticulos = new StoreData(this);
        cursor = stdArticulos.leerArticulos();

        mProgress = (ProgressBar) findViewById(R.id.progressbar_activity);

        new Thread(new Runnable() {
            public void run() {
                while (mProgressStatus < 100) {
                    mProgressStatus = doWork();

                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(mProgressStatus);
                        }
                    });
                }
            }
        }).start();

        if(cursor.moveToFirst()) {
            do{
                strListas[cursor.getPosition()] = cursor.getString(cursor.getPosition());
            }while(cursor.moveToNext());
        }       

        Intent intent = new Intent(MiSuper2.this, PntArticulo.class);
        startActivity(intent);

    }

    public int doWork() {       
        while (fileSize <= 1000000) {
            fileSize++;
            return (int) fileSize;
        }
        return 100;
    }
}

This is the main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imvLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/presentacion" 
        android:contentDescription="@string/logo"/>

    <ProgressBar
        android:id="@+id/progressbar_activity"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="200dp"
        android:layout_height="wrap_content" android:layout_marginTop="100dp"/>

</LinearLayout>

Please help

  • 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-04T05:20:40+00:00Added an answer on June 4, 2026 at 5:20 am

    It looks like you are using the doWork() function to take up time so that you’re progress bar does something. Even though you wrote a big loop, it still executes very quickly so you don’t see your progress bar move. Rather, you want to simulate your Thread doing something computationally intensive by using Thread.sleep() which takes an argument that is the time to sleep in milliseconds.

    Try changing your code to this:

    new Thread(new Runnable() {
        public void run() {
    
            while (mProgressStatus < 100) {
                try {
                    mProgressStatus += doWork();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
    
                mHandler.post(new Runnable() {
                    public void run() {
                        mProgress.setProgress(mProgressStatus);
                    }
                });
            }
    
            runOnUiThread(new Runnable() {
                @Override
                    public void run() {
                        startActivity(new Intent(MiSuper2.this, Second.class));
                    }
                });
            }
    }).start();
    

    And…

    public int doWork() throws InterruptedException {
        Thread.sleep(1000);
        return 1;
    }
    

    This will increment your progress bar by 1% every second. And finally, the documentation on Thread.sleep(): https://developer.android.com/reference/java/lang/Thread.html#sleep(long)

    EDIT: Ramz beat me to this answer, but doesn’t provide an explanation of why it’s the answer. Hopefully my explanation helps.

    EDIT2: I think you edited your questions since I started looking at it a second time. You had some errors in your XML before, but now it is gone. Regardless, your problem is now that you need the call to startActivity() inside your worker thread. Otherwise, the UI thread does not wait for the doWork() function to return and immediately starts the other Activity when your app starts. Sorry, I should have mentioned this before. The code I posted above is updated with this change.

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

Sidebar

Related Questions

Hi i need to show a button after every 120 second for a time
I need show a notication modal window.. But since its a fluid layout the
C# I need to show the time running while the process is doing, shows
I need to implement progress bar in an android project when an intent is
I need to start the activity AlarmReceiver after 10 seconds (for example). I need
me again... I need show 10 or 20 or 50 results number of results
I need to show a modal popup if the user has selected a treeview's
I need to show an integer value in a TextBox in my C# Windows
I need to show the number of results for a given category, and hide
I need to show a page of contents inside my page. ie; when i

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.