1

我遇到了处理程序的问题。我第一次实例化它时它工作正常。

处理程序位于视图内:

    private long delayMillis; 
    private long mMoveDelay = 1000;

    /**
     * Create a simple handler that we can use to cause animation to happen.  We
     * set ourselves as a target and we can use the sleep()
     * function to cause an update/invalidate to occur at a later date.
     */
    private RefreshHandler mRedrawHandler;


    class RefreshHandler extends Handler {

        // serve per far vedere tile 2 almeno un tempo prestabilito checkTime

        @Override
        public void handleMessage(Message msg) {


            delayMillis+=mMoveDelay;
            System.out.println("--->handleMessage mMoveDelay"+10000);
            System.out.println("--->handleMessage delayMillis"+delayMillis);


            sleep();
        }

        public void sleep() {

            //this.removeMessages(0);
            sendMessageDelayed(obtainMessage(0), mMoveDelay);
            System.out.println("--->sleep delayMillis"+delayMillis);
        }
    };

几次后我跑

    mRedrawHandler = new RefreshHandler();
    mRedrawHandler.sleep();

sendMessageDelayed 被立即调用。这篇文章中的问题似乎相似:

Handler.sendMessageDelayed(msg, delay) 无法正常工作

你有什么想法吗?谢谢

4

1 回答 1

0

在 sleep 方法中,obtainMessage(0) 的对象是什么?这似乎是问题所在。您不能使用上次使用的消息对象。你必须创建新的消息对象。

于 2014-12-30T06:39:53.560 回答