From bec7cefcd7d624c8d13075b1c13f80b6de7bc5a5 Mon Sep 17 00:00:00 2001 From: flcstudy Date: Mon, 17 Aug 2026 14:53:02 +0800 Subject: [PATCH] fix: avoid NPE when reading insets controller before setContentView getWindow().getInsetsController() internally calls getDecorView(), which can return null on Android 15/16 (enforced edge-to-edge) when invoked before setContentView(). Guard against a null DecorView so the app no longer crashes on launch. --- .../src/main/java/com/t3code/app/MainActivity.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apk/app/src/main/java/com/t3code/app/MainActivity.java b/apk/app/src/main/java/com/t3code/app/MainActivity.java index 5758079..2f924a2 100644 --- a/apk/app/src/main/java/com/t3code/app/MainActivity.java +++ b/apk/app/src/main/java/com/t3code/app/MainActivity.java @@ -99,11 +99,14 @@ protected void onCreate(Bundle savedInstanceState) { getWindow().setStatusBarColor(Color.parseColor("#161616")); getWindow().setNavigationBarColor(Color.parseColor("#161616")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - WindowInsetsController insetsController = getWindow().getInsetsController(); - if (insetsController != null) { - insetsController.setSystemBarsBehavior( - WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE - ); + View decor = getWindow().getDecorView(); + if (decor != null) { + WindowInsetsController insetsController = decor.getWindowInsetsController(); + if (insetsController != null) { + insetsController.setSystemBarsBehavior( + WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + ); + } } } else { getWindow().getDecorView().setSystemUiVisibility(