Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Android ProgressBar with threads
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Isuru Madusanka  
View profile  
 More options Feb 10 2012, 3:14 pm
From: Isuru Madusanka <isurum....@gmail.com>
Date: Fri, 10 Feb 2012 12:14:47 -0800 (PST)
Local: Fri, Feb 10 2012 3:14 pm
Subject: 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();

}
}

Here is the layout file

<?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>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TreKing  
View profile  
 More options Feb 10 2012, 3:18 pm
From: TreKing <treking...@gmail.com>
Date: Fri, 10 Feb 2012 14:18:11 -0600
Local: Fri, Feb 10 2012 3:18 pm
Subject: Re: [android-developers] Android ProgressBar with threads

On Fri, Feb 10, 2012 at 2:14 PM, Isuru Madusanka <isurum....@gmail.com>wrote:

> 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.

You can't update the UI in a different thread. Use an AsyncTask.

--------------------------------------------------------------------------- ----------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
niko20  
View profile  
 More options Feb 12 2012, 10:04 am
From: niko20 <nikolatesl...@yahoo.com>
Date: Sun, 12 Feb 2012 07:04:32 -0800 (PST)
Local: Sun, Feb 12 2012 10:04 am
Subject: Re: Android ProgressBar with threads
Actually you can update the UI from another thread with either
AsyncTask , or use what is called a Handler, and post a runnable to
the handler. The runnable will then contain the code to update the
progressbar. I usually use the Handler / Runnable method.

-niko

On Feb 10, 2:18 pm, TreKing <treking...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TreKing  
View profile  
 More options Feb 12 2012, 10:47 am
From: TreKing <treking...@gmail.com>
Date: Sun, 12 Feb 2012 09:47:03 -0600
Local: Sun, Feb 12 2012 10:47 am
Subject: Re: [android-developers] Re: Android ProgressBar with threads

On Sun, Feb 12, 2012 at 9:04 AM, niko20 <nikolatesl...@yahoo.com> wrote:
> Actually you can update the UI from another thread

Just to be clear, you cannot update the UI from another thread.
What you do, either via an AsyncTask, Handler, or whatever, is indirectly
update the UI via some messaging mechanism that tells the UI to update in
its main thread.

I know this is what you meant, just making it clear for the OP.

--------------------------------------------------------------------------- ----------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
JackN  
View profile  
 More options Feb 14 2012, 11:10 am
From: JackN <j...@jacknorth.com>
Date: Tue, 14 Feb 2012 08:10:08 -0800 (PST)
Local: Tues, Feb 14 2012 11:10 am
Subject: Re: Android ProgressBar with threads
just send a message to the ui thread telling it to refresh

On Feb 10, 12:14 pm, Isuru Madusanka <isurum....@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nadeem Hasan  
View profile  
 More options Feb 14 2012, 11:28 am
From: Nadeem Hasan <nha...@nadmm.com>
Date: Tue, 14 Feb 2012 08:28:01 -0800 (PST)
Local: Tues, Feb 14 2012 11:28 am
Subject: Re: Android ProgressBar with threads

You want to wait for 5 sec before launching just so that you can show a
progress bar and appear to be doing something important? If you do, just
use a handler instantiated in the activity and post a runnable in the
thread which calls setProgress().


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »