Google AdMob plugin for Cordova, App is closing when we are clicking on the Add and press back button to return to the App

痞子三分冷 提交于 2019-12-10 22:09:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!