Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
phonegap、android、backbutton:can';我做不到_Android_Jquery Mobile_Cordova - Fatal编程技术网

phonegap、android、backbutton:can';我做不到

phonegap、android、backbutton:can';我做不到,android,jquery-mobile,cordova,Android,Jquery Mobile,Cordova,Phonegap 1.8.1——适用于2.2的Android API——jQuery 1.7.1——jQueryMobile 1.0 我已经做了一个非常简单的应用程序来测试这一点,但我就是无法让它工作。给你 INDEX.HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <h

Phonegap 1.8.1——适用于2.2的Android API——jQuery 1.7.1——jQueryMobile 1.0

我已经做了一个非常简单的应用程序来测试这一点,但我就是无法让它工作。给你

INDEX.HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>TestApp</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.css"/>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.1.0/jquery.mobile-1.1.0.min.js"></script>
    <script type="text/javascript">
        function onDeviceReady() {

            document.addEventListener("backbutton", onBackButton);
        }

        function onBackButton(e){
            console.log("C'mon guv! Gimme a chance!");
        }

        document.addEventListener("deviceready", onDeviceReady, false);

    </script>
    <script type="test/javascript" src='cordova-1.8.1.js'></script>

</head>

<body>
<div id="homepage" data-role="page" data-theme="a">
    <div data-role="header">
        <h1>Work with me here</h1>
    </div>

    <div data-role="content">
        I am page 1.
        <a href="#char-1" data-role="button">Next</a>
    </div>
</div>

<div id="char-1" data-role="page" data-theme="a">
    <div data-role="content">HAHAHA!</div>
</div>


</body>
</html>

特斯塔普
函数ondevicerady(){
文件。添加了文本列表(“backbutton”,onBackButton);
}
函数onBackButton(e){
日志(“加油,老兄!给我一个机会!”);
}
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
在这里和我一起工作
我是第一页。
哈哈哈!
AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="2" android:targetSdkVersion="14"/>
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true" />

    <application android:label="@string/app_name">
        <activity android:name="MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest> 

附录-我认为问题在于“deviceready”事件要么不触发,要么在代码绑定到事件之前触发。我不知道怎么修


如果我需要提供更多信息,请告诉我。。我被难住了。

据我所知,back button press事件在onDeviceReady中不起作用。您必须在每页显示中触发事件。就我而言,它是这样工作的

function onDeviceReady(){
    /*Back event handler for all pages navigation*/
    $(document).bind ('pageshow', function (e, data) {
        if ($.mobile.activePage.attr('id') == 'index') {
            document.addEventListener("backbutton", function () { 
                setTimeout( function() {navigator.app.exitApp();}, 100 );
            }, true);
        }
        else{
            document.addEventListener("backbutton", function () {
                setTimeout( function() {$.mobile.changePage("#index");}, 100 );
            }, true);
        }
    });


}

在我的应用程序中,当您从第一个屏幕按下后退按钮时,它将退出应用程序,如果您在任何页面内按下,它将自动进入第一页。

我很惭愧地承认这一点

<script type="test/javascript" src='cordova-1.8.1.js'></script>

这不是测试/javascript。。。它是text/javascript


:(

?它在代码下面。在jquery js在head标记中初始化之前先把它放在前面。这是怎么回事?对我来说仍然不起作用…我是否缺少一些无关的、权限或奇怪的东西?而且它可能在时间线中加载得太晚了。