开发者

How to stop a runner spawned from a method in Android?

I have a method test() inside my onPrepared(Mediaplayer mp) method. The test() spawns a runnable and does the following :

public void test() {
    Runnable playerValues = new Runnable() {
        @Override
        public void run() {
            System.out
                    .println("Player.testPla开发者_如何学编程ying() --> Get Duration : "
                            + vv.getDuration());
            System.out
                    .println("Player.testPlaying() --> Total Bytes Read : "
                            + Download.totalBytesRead);
            System.out
                    .println("Player.testPlaying() --> Current Position : "
                            + vv.getCurrentPosition());
            handler.postDelayed(this, 1000);
        }
    };
    handler.postDelayed(playerValues, 1000);
}

At OnCompletion method of the player i want to stop this Runnable. How can i do that?


Try handler.removeCallbacks(playerValues). (I think you'll want to declare playerValues as a field for that to work, because otherwise handler won't have the scope to see it.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜