android延迟使用处理程序

moe*_*moe 7 android delay handler

我想显示几个图像,并在每个图像之间添加延迟.我这样做并且代码中没有错误但由于某种原因应用程序崩溃了.

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);
Run Code Online (Sandbox Code Playgroud)

Jim*_*ler 34

你没有说什么类主持你发布的代码片段,但我认为handlerTimer.postDelayed((Runnable) this, 20000);不太可能是正确的.

尝试添加匿名Runnable对象,例如

    handlerTimer.postDelayed(new Runnable(){
        public void run() {
          // do something             
      }}, 20000);
Run Code Online (Sandbox Code Playgroud)

另一件事,logcat输出对于获得导致崩溃的原因的线索是非常宝贵的. http://developer.android.com/guide/developing/tools/logcat.html