deckameron / Ti.Android.Admob

Appcelerator Android module wrapping Admob functionalities
17 stars 7 forks source link

I am getting error when opened windows quickly #8

Closed kerberosargos closed 6 years ago

kerberosargos commented 6 years ago

@deckameron hi again. I have an error. My app has got multiple windows. I have created common function in my libs folder as below

var Admob = require("ti.android.admob");
exports.FncCreateAdmobInterstitial = function(_QsContainerWindow) {

                var AdmobInterstitial = Admob.createView({
                    top : 0,
                    adSizeType : "INTERSTITIALAD",
                    publisherId : "xxxxxxxxxxxxxxxxxxxxxxxx", //> USE YOUR PUBLISHER ID HERE
                    testing : false
                });

                _QsContainerWindow.add(AdmobInterstitial);

                AdmobInterstitial.addEventListener('ad_received', function(e) {
                    Titanium.API.warn("Interstital Ad Received");
                });

                AdmobInterstitial.addEventListener('ad_not_received', function(e) {
                    Titanium.API.error("Interstital Ad failed");
                });

                AdmobInterstitial.addEventListener('ad_ready_to_be_shown', function(e) {
                    Titanium.API.warn("Interstital Ad is READY!");
                    AdmobInterstitial.showAdNow();

                });

                AdmobInterstitial.addEventListener('ad_not_ready_yet', function(e) {
                    Titanium.API.warn("Interstital Ad is not ready yet!");
                });

                AdmobInterstitial.addEventListener('ad_being_shown', function(e) {
                    Titanium.API.warn("Interstital Ad being shown right now!");
                });

                AdmobInterstitial.addEventListener('ad_closed', function(e) {
                    Titanium.API.warn("Interstital ad close successfully. RIP!");
                });
            });

I am calling above function as below

mylibs.FncCreateAdmobInterstitial($.windowId);

It is working when I wait and do not press android back button quickly. If I press quickly android back button app is crashing.

Do you have any idea?

deckameron commented 6 years ago

Hi @kerbooo I thing I know what it is. Could you try this version please?

kerberosargos commented 6 years ago

@deckameron Hi again. Firstly Thank you for your support. Unfortunately app is crashing When it is opening. I mean it does not open. May be below debug lines can help you. Thank you for your interest.

[WARN] :   DynamiteModule: Local module descriptor class for com.google.android.gms.ads.dynamite not found.
[WARN] :   System: ClassLoader referenced unknown path:
[WARN] :   System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000013/n/armeabi-v7a
[WARN] :   System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000013/n/armeabi
deckameron commented 6 years ago

@kerbooo thank you for the logs. I will investigate it.

kerberosargos commented 6 years ago

@deckameron I thank you very much. Have a good job..

kerberosargos commented 6 years ago

Hi @deckameron did you find problem?

deckameron commented 6 years ago

@kerbooo not yet. I could not reproduce it yet. But I will keep trying...

kerberosargos commented 6 years ago

@deckameron thank you very much.

kerberosargos commented 6 years ago

@deckameron Hi again. I need to publish new version for my app. Because of that I have changed my approach but this approach is not so useful. May be this approach can help you.

var Admob = require("ti.android.admob");
exports.FncCreateAdmobInterstitial = function() {

                var AdmobInterstitial = Admob.createView({
                    top : 0,
                    adSizeType : "INTERSTITIALAD",
                    publisherId : "xxxxxxxxxxxxxxxxxxxxxxxx", //> USE YOUR PUBLISHER ID HERE
                    testing : false
                });

                var _Window = Titanium.UI.createWindow({
                    backgroundColor : "transparent",
                    theme : "Theme.AppCompat.Translucent.NoTitleBar", 
                });

                _Window.addEventListener("close", function() {
                    _LabelForAdvertisement = null;
                    _Window = null;
                });

                var _LabelForAdvertisement = Ti.UI.createLabel({
                    color : "#2222222",
                    text : "Advertisement",
                    textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER,
                    font : {
                        fontSize : 15
                    },
                    zIndex : 0,
                    backgrounColor: "#000000",
                    borderRadius: 4,
                    width: 100,
                    height: 30
                });

                _Window.add(_LabelForAdvertisement);
                _Window.add(AdmobInterstitial);

                _Window.open();

                _Window.addEventListener('android:back', function(e) {
                    e.cancelBubble = true;
                    return false;
                });

                AdmobInterstitial.addEventListener('ad_not_received', function(e) {
                    _Window.close();
                });

                AdmobInterstitial.addEventListener('ad_ready_to_be_shown', function(e) {
                    AdmobInterstitial.showAdNow();
                });

                AdmobInterstitial.addEventListener('ad_being_shown', function(e) {
                });

                   AdmobInterstitial.addEventListener('ad_closed', function(e) {
                    _Window.close();
                });

mylibs.FncCreateAdmobInterstitial();

kerberosargos commented 6 years ago

@deckameron Could you find a way? Problem source is about closing window before ad load. I mean If you close window before to load ad Interstitial application crash.

deckameron commented 6 years ago

@kerbooo could you try this, please?

Use this version and edit your code like this:

 _Window.addEventListener("close", function() {
    AdmobInterstitial.destoyAdViewAndCancelRequest();
    _LabelForAdvertisement = null;
    _Window = null;
});
kerberosargos commented 6 years ago

@deckameron Unfortunately not. I am getting below error;

[ERROR] :  TiExceptionHandler: (main) [261,74748] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,74748] - In /globalFunctions.js:92,20
[ERROR] :  TiExceptionHandler: (main) [0,74748] - Message: Uncaught Attempt to invoke virtual method 'android.app.Activity org.appcelerator.kroll.KrollProxy.getActivity()' on a null object reference
[ERROR] :  TiExceptionHandler: (main) [0,74748] - Source: AdmobInterstitial.destoyAdViewAndCancelRequest(),
[ERROR] :  V8Exception: Exception occurred at /globalFunctions.js:92: Uncaught Attempt to invoke virtual method 'android.app.Activity org.appcelerator.kroll.KrollProxy.getActivity()' on a null object reference
[ERROR] :  V8Exception: Attempt to invoke virtual method 'android.app.Activity org.appcelerator.kroll.KrollProxy.getActivity()' on a null object reference
deckameron commented 6 years ago

Hi @kerbooo I am in a middle of trip and I can't work on my module right now. I will work on it again when I get back. In the meanwhile, could try something like this code, please?

var Admob = require("ti.android.admob");

exports.FncCreateAdmobInterstitial = function() {

    var _Window = Titanium.UI.createWindow({
        backgroundColor : "transparent",
        theme : "Theme.AppCompat.Translucent.NoTitleBar", 
    });

    _Window.addEventListener("close", function() {
        _LabelForAdvertisement = null;
        _Window = null;
    });

    _Window.addEventListener('android:back', function(e) {
        AdmobInterstitial.removeEventListener('ad_ready_to_be_shown', adReadyToBeShownCallback);
        e.cancelBubble = true;
        return false;
    });

    var adReadyToBeShownCallback = function(e) {
        if(_Window && AdmobInterstitial){
            AdmobInterstitial.showAdNow();
        }
    }

    var AdmobInterstitial = Admob.createView({
        top : 0,
        adSizeType : "INTERSTITIALAD",
        publisherId : "xxxxxxxxxxxxxxxxxxxxxxxx", //> USE YOUR PUBLISHER ID HERE
        testing : false
    });
    _Window.add(AdmobInterstitial);

    AdmobInterstitial.addEventListener('ad_not_received', function(e) {
        _Window.close();
    });

    AdmobInterstitial.addEventListener('ad_ready_to_be_shown', adReadyToBeShownCallback);

    AdmobInterstitial.addEventListener('ad_being_shown', function(e) {
    });

        AdmobInterstitial.addEventListener('ad_closed', function(e) {
        _Window.close();
    });

    var _LabelForAdvertisement = Ti.UI.createLabel({
        color : "#2222222",
        text : "Advertisement",
        textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER,
        font : {
            fontSize : 15
        },
        zIndex : 0,
        backgrounColor: "#000000",
        borderRadius: 4,
        width: 100,
        height: 30
    });
    _Window.add(_LabelForAdvertisement);

    _Window.open();
};

mylibs.FncCreateAdmobInterstitial();
kerberosargos commented 6 years ago

@deckameron Unfortunately not too. 3.0.1 and 3.0.2 release are not working. App crash when it opens. 3.0 release is working but last above codes is giving error too. Thank you for your support.

kerberosargos commented 6 years ago
[WARN] :   TiDrawableReference: (main) [645,645] Could not open stream to get bitmap
[WARN] :   TiDrawableReference: (main) [1,646] Could not open stream to get bitmap
[WARN] :   DynamiteModule: Local module descriptor class for com.google.android.gms.ads.dynamite not found.
[WARN] :   System: ClassLoader referenced unknown path:
[WARN] :   System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000013/n/armeabi-v7a
[WARN] :   System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/00000013/n/armeabi
kerberosargos commented 6 years ago

@deckameron I know I bored you. Could you look this issue?

kerberosargos commented 6 years ago

@deckameron me again. I know really I bored you. Could you look that?

deckameron commented 6 years ago

Hi @kerbooo I finally had some time to work on my module again. Could you please try this version?

kerberosargos commented 6 years ago

Hi @deckameron Unfortunately it does not work too. App crashes when open.

DynamiteModule: Local module descriptor class for com.google.android.gms.ads.dynamite not found.

deckameron commented 6 years ago

@kerbooo are you using these new attributes to create the Interstital View?

publisherId : "ca-app-pub-xxxxxxxxxxxxx~xxxxxxx", //USE YOUR PUBLISHER ID HERE
adUnitId: 'ca-app-pub-xxxxxxxxxxxxx/xxxxxxx', //USE YOUR AD_UNIT ID HERE
kerberosargos commented 6 years ago

@deckameron I have tried after you wrote but I am sorry, result is same.

deckameron commented 6 years ago

@kerbooo import this project into your workspace and tell me if it works, please. Don't forget to replace the adUnitId and publisherId for both ads.

kerberosargos commented 6 years ago

@deckameron Thank you for your effort but result is same. I have extract module from project file and add my project. But app crassh when it was opening. After that import your project my workspace but I get error about SDK version. My project titanium SDK is 7.1.0 GA may be you could tray with SDK 7.1.0 GA.

kerberosargos commented 6 years ago

Hİ @deckameron, I hope you are fine. Did you try codes with SDK 7.1.0?

deckameron commented 6 years ago

Hi @kerbooo I was very busy with a Geofence Module I was creating for a project and could not work on this one for a few weeks. I will go back to it this weekend. ;-)

kerberosargos commented 6 years ago

@deckameron thank you very much. I am waiting :) Have nice work.

kerberosargos commented 6 years ago

Hi @deckameron could you find problem?

kerberosargos commented 6 years ago

Hi @deckameron Firstly thank you and I am sorry. I was building my project with "run-on-main-thread = false" because of that your module crashing when app was opening. I have changed "run-on-main-thread = true" and it is working now. I am sorry again. Thank you for your support.

deckameron commented 6 years ago

@kerbooo I am glad to know everything is ok. I will add this info to the module docs. :-)