nativescript-admob icon indicating copy to clipboard operation
nativescript-admob copied to clipboard

After goBack navigation, admob broke the app

Open calebeaires opened this issue 8 years ago • 4 comments

After topmost goBack, when calling the admob create banner again, I get this error

TypeError: Cannot read property 'addView' of null File: "/data/data/com.example.test/files/app/tns_modules/nativescript-admob/admob.js, line: 127, column: 55"

nativescript-admob: 1.1.4 nativescript: 2.0 emulator: android 6.0

calebeaires avatar May 16 '16 19:05 calebeaires

Can you try fiddling with these lines to fix it?

EddyVerbruggen avatar May 16 '16 19:05 EddyVerbruggen

Removing timeout the problem disappears!

calebeaires avatar May 16 '16 19:05 calebeaires

I've had a problem with this plugin crashing only on certain phones and not every time.

I was able to gain a lot more stability by modifying the plugins code to only use appModule

Changed the following lines in admob.android.js from this:

if (frame_1.topmost() !== undefined) {
   frame_1.topmost().currentPage.android.getParent().addView(adViewLayout_1, relativeLayoutParamsOuter_1);
} else {
   appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout_1, relativeLayoutParamsOuter_1);
}

To this:

appModule.android.foregroundActivity.getWindow().getDecorView().addView(adViewLayout_1, relativeLayoutParamsOuter_1);

After that the crashes stopped.

I even put a check for frame topmost around the firebase instantiation and that didn't help. I found that sometimes popups (permission requests) would interfere with the plugin.

If appModule works more often, why bother with the frame topmost method?

Skintillion avatar Nov 24 '18 23:11 Skintillion

Ok, so if you use the appModule method, it puts the banner behind the navigation buttons.

Going back to the script....


setTimeout(function () {
  if (frame_1.topmost() !== undefined) {
    var topMost = frame_1.topmost();
    var currentPage = topMost.currentPage;
    var currentPageParent = currentPage.android.getParent();
    console.log(currentPageParent); // null
    currentPageParent.addView(adViewLayout_1, relativeLayoutParamsOuter_1);

Even though it finds frame_1.topmost(), the current page parent is null, causing an error when trying to addView.

Skintillion avatar Dec 05 '18 02:12 Skintillion