diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java index 470d98bd..68240c96 100755 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java @@ -217,6 +217,9 @@ public void onDropViewInstance(@NonNull RNNativeAdWrapper view) { if (nativeAdView.unifiedNativeAd != null){ nativeAdView.unifiedNativeAd.destroy(); } + if (nativeAdView.nativeAdView != null){ + nativeAdView.nativeAdView.destroy(); + } } diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java index 5a6cf14c..18d05ec6 100644 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java @@ -145,6 +145,8 @@ public void addMediaView(int id) { } } + private Runnable runnable; + private void setNativeAdToJS(UnifiedNativeAd nativeAd) { try { WritableMap args = Arguments.createMap(); @@ -178,12 +180,13 @@ private void setNativeAdToJS(UnifiedNativeAd nativeAd) { } if (handler != null) { - handler.postDelayed(new Runnable() { - @Override - public void run() { - loadAd(); - } - }, adRefreshInterval); + runnable = new Runnable() { + @Override + public void run() { + loadAd(); + } + }; + handler.postDelayed(runnable, adRefreshInterval); } } @@ -271,14 +274,10 @@ public void requestLayout() { post(measureAndLayout); } - public void removeHandler() { if (handler != null) { - handler.removeCallbacks(null); + handler.removeCallbacks(runnable); handler = null; } - } - - }