Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android delay using handler

I want to display a couple of images and add a delay between each image. I did this and have no errors in the code but for some reason the app crashes.

Bitmap bitmap = BitmapFactory.decodeFile(imageIn);
    ImageView myImageView = (ImageView)findViewById(R.id.imageview);
    myImageView.setImageBitmap(bitmap);
    // Those are the only 2 lines I used to make my handler 
    Handler handlerTimer = new Handler();
    handlerTimer.postDelayed((Runnable) this, 20000);
like image 928
moe Avatar asked Apr 11 '11 15:04

moe


1 Answers

You don't say what class hosts the snippet you posted, but I think handlerTimer.postDelayed((Runnable) this, 20000); is unlikely to be right.

Try adding an anonymous Runnable object such as

    handlerTimer.postDelayed(new Runnable(){
        public void run() {
          // do something             
      }}, 20000);

Another thing, logcat output is invaluable for getting clues about what is causing a crash. http://developer.android.com/guide/developing/tools/logcat.html

like image 186
Jim Blackler Avatar answered Sep 17 '22 17:09

Jim Blackler