Skip to content

fix: android potential crashes, java.lang.RuntimeException: Tried to create view after it has already been destroyed #8052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NormanWangEndeavor
Copy link

What happened?

The app crashes unexpectedly when upgraded from 7.41.1 to 7.44.0.

java.lang.RuntimeException: Tried to create view after it has already been destroyed
  at android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:5148)
  at android.app.ActivityThread.performPauseActivity (ActivityThread.java:5097)
  at android.app.ActivityThread.handlePauseActivity (ActivityThread.java:5049)
  at android.app.servertransaction.PauseActivityItem.execute (PauseActivityItem.java:47)
  at android.app.servertransaction.ActivityTransactionItem.execute (ActivityTransactionItem.java:45)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:177)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:98)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2279)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:201)
  at android.os.Looper.loop (Looper.java:288)
  at android.app.ActivityThread.main (ActivityThread.java:7986)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:553)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
Caused by java.lang.RuntimeException: Tried to create view after it has already been destroyed
  at com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController.getView (ViewController.java:238)
  at com.reactnativenavigation.viewcontrollers.child.ChildController.getView (ChildController.java:37)
  at com.reactnativenavigation.viewcontrollers.statusbar.StatusBarPresenter.setStatusBarVisible (StatusBarPresenter.kt:123)
  at com.reactnativenavigation.viewcontrollers.statusbar.StatusBarPresenter.applyOptions (StatusBarPresenter.kt:41)
  at com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter.applyStatusBarOptions (Presenter.java:108)
  at com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter.onViewBroughtToFront (Presenter.java:64)
  at com.reactnativenavigation.viewcontrollers.child.ChildController.onViewBroughtToFront (ChildController.java:63)
  at com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry.onViewDisappear (ChildControllersRegistry.java:17)
  at com.reactnativenavigation.viewcontrollers.child.ChildController.onViewDisappear (ChildController.java:59)
  at com.reactnativenavigation.viewcontrollers.component.ComponentViewController.onViewDisappear (ComponentViewController.java:110)
  at com.reactnativenavigation.viewcontrollers.parent.ParentController.onViewDisappear (ParentController.java:58)
  at com.reactnativenavigation.viewcontrollers.parent.ParentController.onViewDisappear (ParentController.java:58)
  at com.reactnativenavigation.viewcontrollers.parent.ParentController.onViewDisappear (ParentController.java:58)
  at com.reactnativenavigation.viewcontrollers.parent.ParentController.onViewDisappear (ParentController.java:58)
  at com.reactnativenavigation.viewcontrollers.navigator.Navigator.onHostPause (Navigator.java:283)
  at com.reactnativenavigation.react.NavigationModule$1.lambda$onHostPause$0 (NavigationModule.java:63)
  at com.reactnativenavigation.react.NavigationModule$1.$r8$lambda$1QEZL3bKjVa-AfAQKVEYY2MSdag (Unknown Source)
  at com.reactnativenavigation.react.NavigationModule$1$$ExternalSyntheticLambda1.run (D8$$SyntheticClass)
  at com.reactnativenavigation.utils.UiUtils.runOnMainThread (UiUtils.java:85)
  at com.reactnativenavigation.react.NavigationModule$1.onHostPause (NavigationModule.java:62)
  at com.facebook.react.bridge.ReactContext.onHostPause (ReactContext.java:301)
  at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState (ReactInstanceManager.java:857)
  at com.facebook.react.ReactInstanceManager.onHostPause (ReactInstanceManager.java:604)
  at com.facebook.react.ReactInstanceManager.onHostPause (ReactInstanceManager.java:649)
  at com.reactnativenavigation.react.NavigationReactInitializer.onActivityPaused (NavigationReactInitializer.java:40)
  at com.reactnativenavigation.react.ReactGateway.onActivityPaused (ReactGateway.java:52)
  at com.reactnativenavigation.NavigationActivity.onPause (NavigationActivity.java:85)

What was the expected behavior?

The app should not crash.

Was it tested on the latest react-native-navigation?

I have tested this issue on the latest react-native-navigation release and it still reproduces.

Root Cause

Production crashes occurred after refactoring the status bar logic from Java Presenter.java to Kotlin StatusBarPresenter.kt. The issue stems from how Kotlin handles the viewController.view property:

Previous behavior (Java): Direct field access ViewController.view worked without checks.
Current behavior (Kotlin): viewController.view calls getView(), which checks if the view is destroyed. If the view is already destroyed, this check throws an exception, causing crashes.

In what environment did this happen?

React Native Navigation version: since 7.44.0
React Native version: -
Has Fabric (React Native's new rendering system) enabled: true
Node version: -
Device model: -
Android version: -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant