当在Phonegap中按返回按钮时,将应用程序发送到后台模式 [英] Send Application to background mode when back button is pressed in Phonegap

查看:80
本文介绍了当在Phonegap中按返回按钮时,将应用程序发送到后台模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的phonegap应用程式有问题。

I have a problem with my phonegap application. I want to minimize the application (send App in background so that it's still running) when back button is pressed.

这里是我的代码。

 document.addEventListener("backbutton", onBackKeyDown, false);
 function onBackKeyDown() {
 }

如果我使用 navigator.app.exitApp(); - 我的应用程序将终止
如果我使用 navigator.app.backhistory() - 它会回到上一页。

If I use navigator.app.exitApp(); - my application will terminate and If I use navigator.app.backhistory() - It will just go back to the previous page.

我想要的,如果我按后退按钮,它会发送到主屏幕,并将应用程序发送到背景,以便它仍然在运行。谢谢。

I want that if I press Back button, it will send me to Home screen and send the application to background so that it's still running. Thank you.

推荐答案

您可以使用此插件
然后当设备准备好听backbutton和当onBackKeyDown使用插件启动主屏幕

you can use this plugin then when device ready listen to backbutton and when onBackKeyDown use the plugin to launch the home screen

`document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
    navigator.Backbutton.goHome(function() {
        console.log('success')
    }, function() {
        console.log('fail')
    });
}
`

此插件只是从Dpa99c answer for cordova> = 3的帮助用户

this plugin is just updated from Dpa99c answer for help user with cordova >=3

这篇关于当在Phonegap中按返回按钮时,将应用程序发送到后台模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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