Browse Source

fix: resolve FloatingUIActivity crash on startup

- Move setupTransparentOverlay() from onCreate to onResume to avoid null window
- Add try-catch block to handle WindowInsetsController access errors
- Add null-safety checks for window operations
- Prevent crash when accessing insetsController before window is ready

Fixes: NullPointerException when accessing WindowInsetsController
Error: 'getWindowInsetsController()' on a null object reference

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
feature/modern-capture-ui
Quildra 5 months ago
parent
commit
19a9a2bbe8
  1. 34
      app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt

34
app/src/main/java/com/quillstudios/pokegoalshelper/ui/FloatingUIActivity.kt

@ -74,9 +74,6 @@ class FloatingUIActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Make activity transparent and overlay-capable
setupTransparentOverlay()
// Bind to the ScreenCaptureService
bindToScreenCaptureService()
@ -92,6 +89,12 @@ class FloatingUIActivity : ComponentActivity() {
}
}
override fun onResume() {
super.onResume()
// Setup overlay after window is fully initialized
setupTransparentOverlay()
}
override fun onDestroy() {
super.onDestroy()
if (serviceBound) {
@ -101,16 +104,17 @@ class FloatingUIActivity : ComponentActivity() {
}
private fun setupTransparentOverlay() {
// Make the activity transparent and fullscreen
window.apply {
// Hide system UI (navigation bar, status bar)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
setDecorFitsSystemWindows(false)
insetsController?.let { controller ->
controller.hide(android.view.WindowInsets.Type.systemBars())
controller.systemBarsBehavior = android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
try {
// Make the activity transparent and fullscreen
window?.apply {
// Hide system UI (navigation bar, status bar)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
setDecorFitsSystemWindows(false)
insetsController?.let { controller ->
controller.hide(android.view.WindowInsets.Type.systemBars())
controller.systemBarsBehavior = android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
@Suppress("DEPRECATION")
decorView.systemUiVisibility = (
android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@ -138,6 +142,10 @@ class FloatingUIActivity : ComponentActivity() {
@Suppress("DEPRECATION")
setType(WindowManager.LayoutParams.TYPE_PHONE)
}
}
} catch (e: Exception) {
Log.e(TAG, "Error setting up transparent overlay", e)
// Continue without overlay setup if it fails
}
}

Loading…
Cancel
Save