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

android 监听全局事件homeBack 如果为true 安卓端需要自行调用router.finish方法来关闭应用 #49

Closed
juhuanyan opened this issue Feb 1, 2018 · 2 comments

Comments

@juhuanyan
Copy link

如题,Android具体如何实现

@myliuyx
Copy link
Collaborator

myliuyx commented Feb 1, 2018

Android 会给 前端抛一个 homeBack 的 globaEvent 事件。
你可以监听下这个事件,然后在事件里处理你的返回逻辑, 比如 再按一次退出(调用 router.finish)

@PerseveranceZ
Copy link
Member

demo 示例如下

androidFinishApp () {
        const globalEvent = weex.requireModule('globalEvent')
        globalEvent.addEventListener('homeBack', options => {
            (this.curHomeBackTriggerTimes === this.maxHomeBackTriggerTimes) && this.$router.finish()
            this.curHomeBackTriggerTimes++
            this.$notice.toast({ message: `点击返回${this.maxHomeBackTriggerTimes}次之后,会关闭应用,当前点击第${this.curHomeBackTriggerTimes}次` })
        })
},

首页 methods 里绑定这个方法,然后在 created 里面执行即可。

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

3 participants