如何在Android的使用PhoneGap的jQuery Mobile的设备处理后退按钮? [英] How to handle device back button for Jquery mobile using Phonegap in Android?

查看:189
本文介绍了如何在Android的使用PhoneGap的jQuery Mobile的设备处理后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用jQuery Mobile和PhoneGap的一款使用Android操作系统的应用程序。现在,当我登录到应用程序,它会显示我搜索一些员工。在这个屏幕上我要处理的设备后退按钮。目前,如果我是pressing后退按钮,它是从应用程序注销。但是,我想尽量减少应用程序。这意味着,它不应该注销。刚才我们将应用程序发送到后台(有什么类似Facebook的Andr​​oid应用程序)。我试图处理这一使用下面的code:

I am developing one Android application using jQuery Mobile and Phonegap. Now, when i am log in to the application, it will display me the search some employees. In this screen i want to handle the device back button. Currently if i am pressing the back button, it is logging out from the app. But, i want minimize the app. it means, it should not log out. Just we will send the app to the background(Something similar to facebook android app). I tried to handle this using the below code:

<script type="text/javascript">
            $(document).ready(function() {
document.addEventListener("backbutton", function(e) {
                    alert("ready");
                    navigator.app.exitApp();
                });
            });
        </script> 

下面是我的清单文件:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.innominds.myspace"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
    />

     <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.HARDWARE_TEST" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
             android:configChanges="orientation|keyboardHidden" android:screenOrientation="portrait">
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

但是,当我是pressing后退按钮,它是不是也显示警报。我使用的科尔多瓦2.0和jquery.mobile-1.1.1.js。

But when i am pressing the back button, it is not displaying the alert also. I am using cordova 2.0 and jquery.mobile-1.1.1.js.

我已经得到了<一一些帮助和参考href=\"http://stackoverflow.com/questions/8602722/phonegap-android-back-button-close-app-with-back-button-on-homepage\">here和<一个href=\"http://stackoverflow.com/questions/9631933/override-android-backbutton-behavior-only-works-on-the-first-page-with-phonegap/9739986#9739986\">here.

任何人都可以请帮我..

Can anyone please help me..

推荐答案

您已经错过了在HTML页面中添加cordova.js文件路径。有时这个文件将不会自动在HTML页面中添加人工手动添加这,然后再试一次。

you have missed to add cordova.js file path in your html page. Sometime this file will not be added automatically in html page so add this manually and try again.

如果这行不通删除Android平台和重新添加,并再次添加所有的插件,打造仅适用于Android项目并运行你的问题一定会得到解决。

If this not work remove android platform and add again and add all the plugins once again, build the project only for android and run your problem will definitely will be resolved.

这篇关于如何在Android的使用PhoneGap的jQuery Mobile的设备处理后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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