Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Android ProgressBar with threads

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    18
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Android ProgressBar with threads

    I am working on ProgressBar class in android, but I can't make it progress through 5 seconds and load the application. Everything works but the progress bar not progressing. Here is the code.

    public class StartPoint extends Activity{
     
    ProgressBar progressBar;
    private int progressBarStatus = 0;
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
     
        progressBar = (ProgressBar)findViewById(R.id.progressBar1);
     
     
        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                    while(progressBarStatus < 5000){
                        progressBar.setProgress(progressBarStatus);
                        progressBarStatus += 1000;
     
                    }
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent openMainList = new Intent(StartPoint.this, in.isuru.caf.MainList.class);
                    startActivity(openMainList);
                }
            }
        };
        timer.start();
    }
     
    protected void onPause(){
        super.onPause();
        finish();
    }
    }

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/mary_mother_of_god" />
     
    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.67" />
     
    </LinearLayout>


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: Android ProgressBar with threads

    Also at java-forums.org

    Solution provided at stackoverflow. DIfferent approach suggested at Android Developers (GG).
    Last edited by pbrockway2; February 10th, 2012 at 05:05 PM.

Similar Threads

  1. Android Development
    By bgroenks96 in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: August 30th, 2013, 11:03 PM
  2. Events in Android
    By Nesh108 in forum Android Development
    Replies: 3
    Last Post: February 29th, 2012, 10:49 AM
  3. Hello World Android App
    By TP-Oreilly in forum Android Development
    Replies: 6
    Last Post: January 22nd, 2012, 08:01 PM
  4. How to use Android in (Eclipse || NetBeans)
    By benglish in forum Android Development
    Replies: 2
    Last Post: October 21st, 2011, 07:28 AM
  5. Android Threading api (for bluetooth).
    By new_hope in forum Threads
    Replies: 1
    Last Post: October 1st, 2011, 09:10 AM