播放视频android时未捕获到第一次按下“后退"按钮 [英] First Back button press not caught when playing a video android

查看:65
本文介绍了播放视频android时未捕获到第一次按下“后退"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误,无法弄清楚该如何解决.我有一个视频播放器-一个播放视频的简单videoview.现在,我已经实现了逻辑,以便当用户按下后退"按钮时-告诉用户再次按下后退"按钮退出,并在退出时退出. 但是问题是第一次回压没有被抓住!我不知道是什么原因造成的.一旦没有任何反应,我就按回去,然后再按一次,它显示出吐司说请再按一次退出"的吐司,再按一次则退出.不管我做什么,第一个都不会被抓住.这是OnBackPressed()的代码

I have a weird error that I cant figure out how to fix . I have a video player - a simple videoview that plays a video. Now I ve implemented logic so that when the user presses the back button - it tells him to press the back button again to exit, and when he does it exits. But the problem is the first back press is not caught! I dont know what is causing this. I Press back once nothing happens, I press again and it shows me the toast that says "Please press back again to exit" and on pressing again it exits. The first one is not caught no matter what I do . This is the code for OnBackPressed()

public void onBackPressed() {
        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            finish();
        }

        else {
            this.doubleBackToExitPressedOnce = true;
            Toast.makeText(this, "Please press the back button again to exit",
                    Toast.LENGTH_SHORT).show();
        }
    }

推荐答案

感谢@Satya在

Thanks to @Satya got the answer(Commonsware) at Android back button and MediaController . Basically override dispatchKeyEvent to catch the back button press. @Satya - post your comment as an answer so I can mark it correct, marking this correct until then

这篇关于播放视频android时未捕获到第一次按下“后退"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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