I do not paste all my code. The thread start is in OnClick on some
button as below:

    public void onClick(View v) {
                if(!thumbnailThread.isAlive()){
                        thumbnailThread.start();
    }

Also has other code to change the jpg file for different image.

But now after check the link 
http://android-developers.blogspot.com/2009/05/painless-threading.html,
which i guess is written by you. I use AsyncTask instead. And it works
fine. Thanks for your great blog.

Best Regards
Guoyin Chen

On Jun 16, 11:34 pm, Romain Guy <[email protected]> wrote:
> You MUST NOT touch Views from a background thread. This means calls to
> findViewById() and setImageBitmap() should not be running on the backgorund
> thread in your case.




> Also, you do not start() the thread and you always set the *same* image on
> the ImageView. I doubt you will see much difference :)
>
>
>
>
>
> On Tue, Jun 16, 2009 at 1:38 AM, waterblood <[email protected]> wrote:
>
> > Dear all,
>
> >   I cannot make postInvalidate() work in non-UI thread in sdk1.5.
> > Below are my code, let me know if i am wrong in some place. It is
> > supposed to update imageview every seconds. But it never be updated
> > from the bitmap.
>
> > public class ThumbnailActivity extends Activity  implements
> > OnClickListener{
> >        private static final String TAG = "FSL MM Thumbnail TEST";
> >        private Thread thumbnailThread;
> >        private boolean thumbnailStoped = false;
>
> >    /** Called when the activity is first created. */
> >   �...@override
> >    public void onCreate(Bundle savedInstanceState) {
> >        Log.i(TAG,"ThumbnailActivity onCreate");
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.thumbnail);
>
> >        thumbnailStoped = false;
> >        thumbnailThread = new Thread(new Runnable() {
> >            public void run() {
> >                        Log.i(TAG,"***thumbnailThread run***");
> >                        while(! thumbnailStoped ) {
> >                                 Bitmap bitmap;
> >                                 ImageView thumbimage;
> >                                 thumbimage = (ImageView)findViewById
> > (R.id.thumbnail_image);
> >                                 bitmap = BitmapFactory.decodeFile("/sdcard/
> > some.jpeg");
> >                                 if(bitmap == null)
> >                                         Log.i(TAG,"Error!not get bitmap
> > from .jpg");
> >                                 thumbimage.setImageBitmap(bitmap);
> >                                 thumbimage.postInvalidate();
>
> >                                Log.i(TAG, "***thumbnailThread
> > continue running***");
> >                                SystemClock.sleep
> > (1000);
> >                              }
> >                       });
>
> >    }
>
> > }
>
> > the xml of layout as below:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
> > android"
> >    android:layout_width="fill_parent"
> >    android:layout_height="fill_parent">
>
> >    <Button
> >        android:id="@+id/thumbnail_autopreview_button"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content"
> >        android:layout_alignParentLeft="true"
> >        android:layout_marginTop="8dip"
> >        android:layout_marginLeft="10dip"
> >        android:text="Auto"
> >    />
>
> >    <Button
> >        android:id="@+id/thumbnail_nextimage_button"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content"
> >        android:layout_toRightOf="@id/thumbnail_autopreview_button"
> >        android:layout_alignTop="@id/thumbnail_autopreview_button"
> >        android:layout_marginLeft="10dip"
> >        android:text="Next"
> >    />
>
> >    <Button
> >        android:id="@+id/thumbnail_stoppreview_button"
> >        android:layout_width="wrap_content"
> >        android:layout_height="wrap_content"
> >        android:layout_toRightOf="@id/thumbnail_nextimage_button"
> >        android:layout_alignTop="@id/thumbnail_nextimage_button"
> >        android:layout_marginLeft="10dip"
> >        android:text="Stop"
> >    />
>
> >    <TextView
> >        android:id="@+id/filename_label"
> >        android:layout_width="fill_parent"
> >        android:layout_height="wrap_content"
> >        android:text="File: /sdcard/hello.mp4"
> >        android:layout_below="@id/thumbnail_stoppreview_button"
> >    />
>
> >    <ImageView
> >        android:id="@+id/thumbnail_image"
> >        android:layout_width="fill_parent"
> >        android:layout_height="fill_parent"
> >        android:layout_marginLeft="4dip"
> >        android:layout_marginRight="2dip"
> >        android:layout_marginTop="8dip"
> >        android:layout_below="@id/filename_label"
> >    />
> > </RelativeLayout>
>
> > Best Regards
> > Guoyin Chen
>
> --
> Romain Guy
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support.  All such questions should be posted on public
> forums, where I and others can see and answer them
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to