PhoneGap的的Andr​​oid - 检测home键? [英] Android Phonegap - detect home button?

查看:91
本文介绍了PhoneGap的的Andr​​oid - 检测home键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本监视机器人后退按钮的动作 -

I have the following script that monitors the android back button actions -

document.addEventListener("backbutton", backKeyDown, true); 


function backKeyDown() { 


if($.mobile.activePage.is('#homepage')){
  setTimeout( function() {navigator.app.exitApp();}, 100 );

}
else {
    setTimeout( function() {$.mobile.changePage("#homepage");}, 100 );

}

}

我想也关闭应用程序时的物理Home键pssed $ P $ - ?没有人知道如何检测这个

I would like to also close the app when the physical home button is pressed - does anyone know how to detect this?

干杯
保罗

推荐答案

您不能这样做,但你可以杀死的onPause您的应用程序()方法,而不是看多这里

You can't do that but you can kill your app in onPause() method instead see more here

编辑:

这样做,在会的onPause让你的应用程序被杀每当用户离开该活动,我不知道是否有一种方法做,你在Android中想要什么,虽然,也不是推荐!

Doing that in onPause will get your app killed whenever the user leaves the activity, I am not sure if there is a way to do what you want in android though, also is not recommended!

您可以创建一个从活动到应用程序实例在给定的时间间隔将消息发送一些复杂的广播消息系统,如果你没有得到在x秒的应用程序实例的任何消息,那么你知道,应用程序是在后台..

You can create some complex broadcast messaging system that sends messages from your activities to the application instance at a given interval of time and if you don't get any message in the application instance for x seconds then you know that the app is in background..

您可以做到这一点使用,直到在onPause被调用,并延长所有你使用,因此你可以有这种行为的其他活动,该活动在x秒发送消息的基础活动课。

You can do that using a base activity class that sends messages at x seconds until onPause is called and extend that activity in all the other activities that you use so you can have this behaviour.

这是肯定不是最好的选择就是在那里,会消耗电池寿命取决于执行,所以你必须要真正确保你实现这样的事情之前,需要这个。

This is for sure not the best option that is out there and will consume battery life depending on the implementation so you have to be really sure that you need this before implementing such thing.

这篇关于PhoneGap的的Andr​​oid - 检测home键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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