Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
fix(Hide interstitial ads): Crashing when trying to hide
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Feb 14, 2024
1 parent 6656f1a commit f898e7d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ public class InterstitialBannerPatch {
/**
* Last time method is called
*/
private static long lastTimeCalled = 0;
private static volatile long lastTimeCalled = 0;
private static final Instrumentation instrumentation = new Instrumentation();

public static void onBackPressed() {
final long currentTime = System.currentTimeMillis();
if (lastTimeCalled != 0 && currentTime - lastTimeCalled < 10000)
return;

lastTimeCalled = currentTime;
ReVancedUtils.runOnMainThreadDelayed(() -> new Thread(() -> new Instrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_BACK)).start(), 1000);
ReVancedUtils.runOnMainThreadDelayed(() -> {
// Must run off main thread (Odd, but whatever).
ReVancedUtils.runOnBackgroundThread(() -> instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK));
}, 1000);
ReVancedUtils.runOnMainThreadDelayed(() -> ReVancedUtils.showToastShort(str("revanced_close_interstitial_ads_toast")), 1000);
}
}

0 comments on commit f898e7d

Please sign in to comment.