From aa4353a81bf7f93d63bdfa986b589f5663e36020 Mon Sep 17 00:00:00 2001 From: Henrique Silva <86384056+hgapsilva@users.noreply.github.com> Date: Wed, 24 Jan 2024 12:39:05 +0000 Subject: [PATCH] Update VolumeManagerModule.java when having native with a react native fragment, after entering that fragment and then using the back hardware, the app crashes --- .../com/reactnativevolumemanager/VolumeManagerModule.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/reactnativevolumemanager/VolumeManagerModule.java b/android/src/main/java/com/reactnativevolumemanager/VolumeManagerModule.java index b081cfa..b370511 100644 --- a/android/src/main/java/com/reactnativevolumemanager/VolumeManagerModule.java +++ b/android/src/main/java/com/reactnativevolumemanager/VolumeManagerModule.java @@ -293,9 +293,11 @@ private int getVolType(String type) { private void cleanupKeyListener() { runOnUiThread(() -> { if (!hardwareButtonListenerRegistered) return; - View rootView = - ((ViewGroup) mContext.getCurrentActivity().getWindow().getDecorView()); - rootView.setOnKeyListener(null); + if (mContext.getCurrentActivity() != null) { + View rootView = + ((ViewGroup) mContext.getCurrentActivity().getWindow().getDecorView()); + rootView.setOnKeyListener(null); + } hardwareButtonListenerRegistered = false; }); }