javascript 完全关闭phonegap android应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7423776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fully Closing a phonegap android app
提问by Sathariel
How do I fully close a PhoneGap Android app? I've tried using device.exitApp() as well as navigator.app.exitApp() and have the same problem with both.
如何完全关闭 PhoneGap Android 应用程序?我试过使用 device.exitApp() 以及 navigator.app.exitApp() 并且两者都有相同的问题。
The problem is that I have an html file, index.html, that links to an external html file, main.html. Now if I hit the close button without going to the external file, the app closes just fine. If I go to the external file and then go back to index then hit close, it closes index but brings up main. How do I completely close the app whether or not I go the external page?
问题是我有一个 html 文件 index.html,它链接到外部 html 文件 main.html。现在,如果我在不访问外部文件的情况下点击关闭按钮,应用程序就会关闭。如果我转到外部文件然后返回索引然后点击关闭,它会关闭索引但会显示主文件。无论是否转到外部页面,如何完全关闭应用程序?
Index.html
索引.html
<html>
<head>
<script type="text/javascript" src="Scripts/phonegap-1.0.0.js"></script>
</head>
<body>
<a href="index.html">Index</a>
</body>
</html>
Main.html
主文件
<html>
<head>
<script type="text/javascript" src="Scripts/phonegap-1.0.0.js"></script>
</head>
<body>
<a href="index.html">Index</a>
</body>
</html>
Android Manifest
安卓清单
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap"
android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
</activity>
</application>
采纳答案by Devgeeks
This was how PhoneGap Android worked with PhoneGap 1.0.0.
这就是 PhoneGap Android 与 PhoneGap 1.0.0 的工作方式。
This behaviour has changed to more like what you are expecting in PhoneGap 1.1.0. Try upgrading.
此行为已更改为更像您在 PhoneGap 1.1.0 中所期望的。尝试升级。
http://simonmacdonald.blogspot.com/2011/10/changes-in-phonegap-android-110.html
http://simonmacdonald.blogspot.com/2011/10/changes-in-phonegap-android-110.html
"Now when you are dealing with multiple page apps there is a change to navigator.app.exitApp(). This command now exits the app completely it does not return to the previous page. If you want to go back a page you should use navigator.app.backHistory()."
“现在,当您处理多个页面应用程序时,navigator.app.exitApp() 发生了变化。此命令现在完全退出应用程序,它不会返回上一页。如果您想返回一个页面,您应该使用navigator.app.backHistory()。”