问题
I am using Cordova frame work to build an app,I had used Google AdMob plugin for Cordova to show the Adds in my App, and My problem is when user click on any add and tries to come back to the App by clicking back button the App was closing and the user has to start it from the beginning, what i need to do to over come this issue , Thanks in Advance...
回答1:
Try adding following code in your Cordova Project Main Activity file after onCreate method -
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
回答2:
I am author of the admob plugin: https://github.com/floatinghotpot/cordova-admob-pro
Your problem is not related with the plugin, but with the cordova default behavior.
You can override the back-button behavior, then Cordova APP will not exit when user click back-button.
To override the default back-button behavior, register an event listener for the backbutton event, typically by calling document.addEventListener once you receive the deviceready event. It is no longer necessary to call any other method to override the back-button behavior.
Here is the sample javascript code:
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
}
For more details, read the cordova doc: https://cordova.apache.org/docs/en/4.0.0/cordova_events_events.md.html
来源:https://stackoverflow.com/questions/29259700/google-admob-plugin-for-cordova-app-is-closing-when-we-are-clicking-on-the-add