do this : http://android-developers.blogspot.com/2009/05/painless-threading.html
On Jun 16, 3: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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

