From af86cf8f22e629919510542ac4a5d13b41193247 Mon Sep 17 00:00:00 2001 From: tapanmodh Date: Thu, 12 Jan 2023 00:32:21 +0530 Subject: [PATCH] fix brave news crash on ntp in android --- .../browser/ntp/BraveNewTabPageLayout.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java index eb084bda80b6..a23b8791588f 100644 --- a/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java +++ b/android/java/org/chromium/chrome/browser/ntp/BraveNewTabPageLayout.java @@ -302,20 +302,21 @@ protected void onAttachedToWindow() { } if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_NEWS)) { initBraveNewsController(); - if (BraveActivity.getBraveActivity() != null - && BravePrefServiceBridge.getInstance().getNewsOptIn()) { + if (BravePrefServiceBridge.getInstance().getNewsOptIn()) { new Handler(Looper.getMainLooper()).post(() -> { - Tab tab = BraveActivity.getBraveActivity().getActivityTab(); - if (tab != null && tab.getUrl().getSpec() != null - && UrlUtilities.isNTPUrl(tab.getUrl().getSpec())) { - // purges display ads on tab change - if (BraveActivity.getBraveActivity().getLastTabId() != tab.getId()) { - if (mBraveNewsController != null) { - mBraveNewsController.onDisplayAdPurgeOrphanedEvents(); + if (BraveActivity.getBraveActivity() != null) { + Tab tab = BraveActivity.getBraveActivity().getActivityTab(); + if (tab != null && tab.getUrl().getSpec() != null + && UrlUtilities.isNTPUrl(tab.getUrl().getSpec())) { + // purges display ads on tab change + if (BraveActivity.getBraveActivity().getLastTabId() != tab.getId()) { + if (mBraveNewsController != null) { + mBraveNewsController.onDisplayAdPurgeOrphanedEvents(); + } } - } - BraveActivity.getBraveActivity().setLastTabId(tab.getId()); + BraveActivity.getBraveActivity().setLastTabId(tab.getId()); + } } }); }