为什么我的CountDownTimer不计算?

时间:2014-04-25 04:23:36

标签: android

我在for循环中有一个CountDownTimer,但它不算数。为什么呢?

for (int i = 0; i < payloadList.size(); i++) {
                sonpx.dtnsocialnetwork.Bundle bundle = new sonpx.dtnsocialnetwork.Bundle(
                        srcIMEI, desIMEI, fileName, i, totalFragment,
                        numOfSendingRest, payloadList.get(i));
                byte[][] payload = new byte[1][];
                try {
                    payload[0] = serialize(bundle);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                Log.i(TAG, "bundle payload size: "+payload[0].length);
                mDefaultChannel.sendData(nodeName, DIRECT_BUNDLE, payload);

                CountDownTimer countDownTimer = new CountDownTimer(5000, 100) {
                    @Override
                    public void onTick(long millisUntilFinished) {
                        if (bundleResultOk) {
                            cancel();
                            bundleResultOk = false;
                        }
                        Log.i(TAG, "bundle result: "+bundleResultOk);
                    }

                    @Override
                    public void onFinish() {
                        counterFinish = true;
                        Log.i(TAG, "Send Message time out");
                    }
                };
                countDownTimer.start();
}

它不会打印Log.i(TAG,&#34;捆绑结果:&#34; + bundleResultOk);

2 个答案:

答案 0 :(得分:0)

可能代码没有在HandlerThread中运行

答案 1 :(得分:0)

使用此自定义CountdownTimer