Android,暂停和恢复处理程序回调 [英] Android, pausing and resuming handler callbacks

查看:27
本文介绍了Android,暂停和恢复处理程序回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用的处理程序,如下所示:

I have a handler that I am using as follows:

handler.postDelayed(Play, 1000);

当我的应用程序 onPause() 在完成之前被调用时,我需要暂停它并告诉它在我恢复之前不要执行postDelayed".

when my application onPause() is called before this is done, I need to pause it and tell it not to perform the "postDelayed" until I resume.

这是可能的,还是有其他方法?

is this possible, or is there an alternative way?

我的问题是,当 onPause() 被调用时,我会暂停音频 (SoundManager),但如果在此之后调用此 handler.postDelayed,音频将不会暂停,并将继续在后台播放我的应用程序.

My problem is that when onPause() is called I pause the audio (SoundManager), but if this handler.postDelayed is called after that, the audio will not be paused and will continue to play with my application in the background.

@Override
public void onPause()
{
  Soundmanager.autoPause()
}

但是 1000 毫秒后的 postDelayed 再次开始播放音频.

but then the postDelayed after 1000ms starts the audio playing again.

推荐答案

您是否尝试过:

@Override
public void onPause()
{
  handler.removeCallbacks(Play);
  Soundmanager.autoPause()
}

德国

这篇关于Android,暂停和恢复处理程序回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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