检测后退按钮点击和忽略额外的点击 [英] Detecting Back Button Clicks and Ignoring Extra Clicks

查看:112
本文介绍了检测后退按钮点击和忽略额外的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有时会在用户点击后退按钮,并没有任何反应,所以他们再次单击右走,而不是回到previous屏幕他们去2-3屏幕后面。有时出完全的应用程序。然而,这些回点击,而被证明只是一个屏幕上的所有发生!有什么办法来拦截这一点,并忽略这些跟进回来点击。或许,观察它们的间距或它们发生的屏幕?没有任何人有这个问题?

In my app sometimes the user clicks on the back button, and there is no response, so they click again right away, and instead of going back to previous screen they go 2-3 screens back. Sometimes out of the app entirely. And yet these back clicks all occured while just one screen was shown! Is there any way to intercept this and ignore these follow up back clicks. Perhaps observe their spacing or the screen in which they occured? Does anyone else have this problem?

我的猜测是没有什么可以做,因为用户已超过后退按钮的最终控制权,但为什么没有Android的忽略额外的点击,因为它们都发生在同一页上,它甚至还没有表示切换??

My guess is nothing can be done because the user has ultimate control over back button, but why does Android not ignore the extra clicks since they all happen on the same page and it has not even stated to switch??

推荐答案

您可以用低于code容易患后退按钮,但你其实它不应该采取永远回应。你的UI线程被阻塞做一些事情,这是根本错误的。

You can catch the back button easily with the below code, however you should really not be taking forever to respond. Your UI thread is blocked doing something and this is fundamentally wrong.

@Override
public void onBackPressed() {
  // do something on back.
  return;
}

这篇关于检测后退按钮点击和忽略额外的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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