如何停止从 Android 中的方法生成的运行程序?
我的 onPrepared(Mediaplayer mp) 方法中有一个方法 test() 。 test() 生成一个可运行对象并执行以下操作:
public void test() {
Runnable playerValues = new Runnable() {
@Override
public void run() {
System.out
.println("Player.testPlaying() --> 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);
}
在播放器的 OnCompletion 方法中,我想停止此可运行对象。我怎样才能做到这一点?
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.testPlaying() --> 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试处理程序。removeCallbacks(玩家值)。 (我认为您需要将playerValues声明为一个可以正常工作的字段,因为否则处理程序将没有范围来查看它。)
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.)