android使用处理程序延迟 [英] android delay using handler

查看:102
本文介绍了android使用处理程序延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

推荐答案

您没有说哪个类托管着您发布的摘录,但我认为handlerTimer.postDelayed((Runnable) this, 20000);不太可能是正确的.

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

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

Try adding an anonymous Runnable object such as

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

另一方面,logcat输出对于了解导致崩溃的线索非常有用. http://developer.android.com/guide/developing/tools/logcat.html

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

这篇关于android使用处理程序延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆