Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainActivity中onBackPressedSupport()方法监听返回键问题 #11

Closed
huang-yongTech opened this issue Jul 28, 2018 · 2 comments
Closed

Comments

@huang-yongTech
Copy link

您好,我想问下您在app中的再按一次返回键退出这个功能是怎么实现的?我代码也是这样设置的,但是没效果啊,您在别的地方是不是也有相关的设置?
我的MainActivity里面代码是这样的:

    // 再点一次退出程序时间设置
    private static final long WAIT_TIME = 2000L;
    private long TOUCH_TIME = 0;

    @Override
    public void onBackPressedSupport() {
        super.onBackPressedSupport();

        if (getFragmentManager().getBackStackEntryCount() > 1) {
            //如果当前存在fragment>1,当前fragment出栈
            pop();
        } else {
            //如果已经到root fragment了,2秒内点击2次退出
            if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
//                setIsTransAnim(false);
                finish();
            } else {
                TOUCH_TIME = System.currentTimeMillis();
                Toast.makeText(this, "再按一次退出", Toast.LENGTH_SHORT).show();
            }
        }
    }
@Horrarndoo
Copy link
Owner

这句super.onBackPressedSupport(); 调用父类onBackPressedSupport删掉;

@huang-yongTech
Copy link
Author

解决了,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants