Skip to content Skip to sidebar Skip to footer

Google AdMob Plugin For Cordova, App Is Closing When We Are Clicking On The Add And Press Back Button To Return To The App

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 c

Solution 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();
}

Solution 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


Post a Comment for "Google AdMob Plugin For Cordova, App Is Closing When We Are Clicking On The Add And Press Back Button To Return To The App"