-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
Android crash: "Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment" #1644
Comments
Hey! 👋 The issue doesn't seem to contain a minimal reproduction. Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem? |
I'll try to make a repro outside of my project, but i can't guarantee that the issue will be reproducible in most devices |
I also tried to disable screens, but it didn't work, tha app just crashes in a different manner |
Hi @valn1, the steps you pointed out are described in installation instructions of the library and must be followed to assert that the library works properly. Explanation why this is needed, and can't be really bypassed is also in discussion of #17 (direct link to comment).
If the app crashes with disabled Moreover to work with this issue I would need a reliable reproduction. |
i also thought it could be a different lib that was causing the issue instead of rn screens, but when screens are disabled, the same error happens, it just looks different to the user and yes, overriding the onCreate method with null parameter does prevent the app from crashing, but the work that was being done is lost anyways because the app restarts |
i would like to understand better how this error happens and why the savedInstanceState is so unreliable. |
Sorry for the late response! The main reason we require these installation steps is to avoid inconsistencies between native & JS view hierarchies (and corresponding state). When OS kills your application and you save your native state, the same thing does not happen for JS state. Therefore, while restoring you can bring back native state (and even make the views look the same for a while), but you can't do the same with JS, thus it would lead to inconsistencies and bugs. I'm gonna close the issue, as it was already discussed in #17, however feel free to ping me & continue the discussion, maybe we will come up with something. |
By adding the workaround fix mentioned, my other fragments in the code started crashing: Fatal Exception: java.lang.IllegalStateException: Fragment no longer exists for key f#0: unique id 0b6a09fd-22ff-413b-ad75-4512fc6f6d6b |
This fixed my problem. |
Hello everyone, |
@kabottin0 probably happens only when the Operating System kills the application in the background, try changing your phone configs to have a maximum of 1 app opened at a time, open your app and then, open a different one and finally, switch to your app, that will trigger the onCreate method which will break as the savedInstance is no longer available |
yesterday i also updated to the latest React native version 74.1 and updated all packages that are related to react-native-screens. But still the same error. I thought it might be related to react-native": ‘0.73.2’, but unfortunately it was not. I'm slowly running out of ideas. Has anyone else found a solution? |
Hey @alialim, are you able to provide a reproduction of this issue? |
I am using latest React Native Version 0.74.2. I have a mainactivity.kt inside android/app/src/main/java how to fix this issue please help anyone |
seeing thew same on React Native Version 0.74.3 |
@phil-hudson @FazilMuhammed unfortunatelly i haven't been able to fix this issue myself. what i did was work around it, you gotta find out what action makes your app crash, then make the app do something else instead. and so i got around the crash by literally avoiding it. my solution was very convoluted and demanded a whole new module to my app, but you could probably just rewrite the bit that breaks and do it differently so it does not crash anymore. |
i have this error but only when user open my react native app, go to android settings, change font size and come back on app |
Have you tried adding this to your MainActivity.kt file? override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null)
} |
In my case, this issue happens with every trigger to Alert.alert(), so I just replaced it with Custom Alert components, also I used react-native-flash-message, however, this is still a workaround, I hope it helps someone. |
@muxbert @FazilMuhammed |
This comment was marked as off-topic.
This comment was marked as off-topic.
When I tried this my app started crashing normally in addition to the background. Also i got a new error. I added the error below |
Description
I am using react-native-image-picker and react-native-screens in my application.
about half of the times i try to pick an image taken by the camera, the app crashes throwing
AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/com.app.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenFragment: calling Fragment constructor caused an exception
I found this answer in another closed issue
#17 (comment)
but it does not work for my app because, i need to have the saved instance of the app being reopened, wich doesn't happen if i set it to null(the app restarts).
this bug only happens in a few devices tested positive for motorola one hyper and motorola moto g8 power and only happens sometimes
Steps to reproduce
execute launchCamera from 'react-native-image-picker'
click ok(or similar) after taking a picture
and the app will crash when returning to the application
Snack or a link to a repository
Screens version
3.18.2
React Native version
0.70.6
Platforms
Android
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Paper (Old Architecture)
Build type
Release mode
Device
Real device
Device model
motorola one hyper
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: