问题
I am making an app for Android using HTML-JavaScript on Intel-XDK. I'm overriding the Android Back Button function and Android Menu Button using the following code.
<script src="cordova.js" type="text/javascript"></script>
<script type="text/javascript">
/* Android Back Button
----------------------------------------------- */
function backButtonPressed() {
isPaused = true; // To Pause
}
document.addEventListener("backbutton", backButtonPressed, false);
/* Android Menu Button
----------------------------------------------- */
function menuButtonPressed() {
isPaused = false; // To false
}
document.addEventListener("menubutton", menuButtonPressed, false);
</script>
Both are working perfectly in Intel-XDK Emulate. But when I am running them in an android device, the menu button code is working but back button code is not working and it's exiting the app. What to do to stop this behavior (ie, exiting the app) and start running my own code?
Note: I also tried code from https://software.intel.com/en-us/node/493108 but still not working in Mobile and is working in Emulator.
回答1:
Finally got the solution of this problem and that is the popup that I was ignoring.
In short, App Preview, Emulator or the Debug Tab are not perfect to give you the perfect answer so take decisions after building the APK and installing it on your device.
回答2:
Try to run your code on real devices or emulators which are using Intel microprocessors. Maybe it must be compiler optimization problem, which are not optimizing to same level for non Intel microprocessors as mentioned in the optimization notice. Try to run it on Intel microrocessor AVD (Android Virtual Device). You can make one as mentioned in the Android developer guide.
来源:https://stackoverflow.com/questions/34511358/android-back-button-exiting-apps-instead-of-running-its-new-code