-
-
Notifications
You must be signed in to change notification settings - Fork 521
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 crashes nondeterministically when restoring from background #17
Android crashes nondeterministically when restoring from background #17
Comments
😱 |
As a workaround for this issue I suggest adding the following code to the main activity class (the one that extends
|
We should perhaps make it a default behavior for the main activity class in RN core as restoring instance state won't work in RN this way anyways |
Agreed. Generally speaking if you cannot save your JS memory (Redux stores, in-component state etc.), then saving only your view state could likely cause inconsistencies. But then again in a single-activity-app, not saving the activity state means that your app is essentially restarting whenever OS kills your activity for any reason. Does react-native-navigation attempt to deal with process death challenge, I don't know. Maybe it'd be better to let to the hosting navigation libraries deal with this. In practice they could keep saving each new screen props on into a bundle in the main activity, put this bundle into the one given in Btw my app doesn't have this problem as we have an architecture (not using this library, but I'd like to in the future) where each screen is an instance of an activity, and the props are sent through converting a ReadableMap into a Bundle and storing the Intent extras. This way we never lose the props at process death, and the props are usually sufficient to recreate the flow the user had left the app in. Not necessarily advocating for multiple activities but just explaining how we solved it. |
I hit this issue too, maybe we should add the workaround in the installation instructions. It is easy to reproduce by using the dev settings to kill background activities. |
Going to add that @janicduplessis Thanks @hey99xx for your input. The thing is that RN app is not able to restore the app state properly. So even if we were able to bring back all the views from the previous state the app won't be able to pick that up and start from there. Now when system kills the app it starts all over. In fact Android restore mechanism isn't really reliable even outside RN apps, you can try enabling developer option "don't keep activities" for a day to see it does not work in most of the apps (even some parts of the gmail app). React-native-navigation does not deal with that either, in fact it does not rely either on activities nor fragments, just have their own containers based off of ViewGroup, so behaves exactly the same way as any other RN app with regard to that. Having each screen launch an app using |
I understand your reasonings and that's what I mentioned in my first paragraph too, saving only your view state is solving only half of the problem, and will cause inconsistencies as your Redux state will be entirely gone unless you find ways to persist it (I guess redux-persist could work here). I don't think we have a disagreement here.
This is also true, but from my experience props tend to be sufficient, and saving further state in the activity is not super necessary. In fact this approach is a bit similar to We have this architecture not necessarily because it's the best but because we have a hybrid app and we need to be able to have activity stacks where some are RN based and some are pure native, so we cannot use any traditional navigation libraries. Otherwise I already understand the downsides of our activity per screen solution.
|
Thanks @hey99xx I think we are on the same page with regard to that |
The workaround doesn't solve it for me - anyone found something else which could cause this? |
facing same crash here |
+1 |
Thanks @K-Leon @jgcmarins @joaodematejr for leaving your notes. I'd appreciate it very much if you could find a minute to include a stacktrace from the crash you are experiencing and also version of the library + RN version your app uses. |
|
@jgcmarins can you please try it with [email protected] then? @K-Leon thanks for sending the stacktrace but it is missing the top of the trace (where the exception is specified) which is the most important part. Also if exception has a cause ("caused by" section) that would be an important information too |
@kmagiera version I also updated to rn 0.59. |
Hello, I am on rn 0.58.6 and
ill try to upgrade to 59 later |
Here's another occurrence with the latest version of screens (alpha 22), with the full stacktrace in a release build.
The exception root is in this line. |
I am now facing a crash after closing the app and opening it again. |
@jgcmarins did this ever get resolved for you? |
Sorry, can't confirm because I am not working on that app anymore. Maybe @sibelius can help with this answer. |
fixed for us |
This bug was fixed for me. When I downgraded to react-native-screens@^2.15.0 |
Tested it with multiple devices as well, seems like a better approach and setup for the readme as suggested. |
So hit that edit button and make a PR :-) |
I'm using this code but unfortunately there are still a few people (100 in 7 days) that crashes during onPause, we're also using codepush so it could be another factor Or maybe this error of mine is unrelated D;
|
@marqroldan I believe it is this one: #463, and there is a solution provided, but it needs to be tested thoroughly: #463 (comment) |
Add this on activity
|
This code makes NullPointerException |
|
@WoLewicki Has there been a fix or support added for restoring screen fragments? What are the repro steps? I'm on react-native 0.63.3 and react-native-screens 3.4.0, and we are starting to see this crash in our app in production. We haven't added the first recommended fix of passing null into onCreate since we want to preserve state if the app is relaunched from the background - but I also haven't been able to repro this locally. Any help here would be appreciated to better understand what's going on and what's the current state of things. |
as comment suggested pass null to onCreate, however, on foldable phone the whole application will restart whenever we split into multi-window. Any other ways could prevent such issue? Thanks. |
@mikehardy is this the better fix (with the null guard)? |
Probably yes, but as with anything, test it in use |
Any screen rotation, permission change, language change, theme change etc also represent what android calls configuration changes and they all restart the app. Save nav state and dehydrate rehydrate in app |
Would love to but so far this issue only happens with deployed versions out there. I was never able to reproduce it. Any idea how to force it? |
@lkw1830 you can fix that issue by setting up So eg. here in our example app set it as
When I was testing this setting up Source: https://developer.android.com/guide/topics/manifest/activity-element#config |
@kacperkapusciak that's a neat trick and a good strategy! I do similar, but I still have the Bundle-clearing workaround as well, as what I fear happens (and what appears to have happened with at least 'smallestScreenSize' is that new config items are added to the list of things that can cause an Activity restart without me realizing it, resulting in a new vector for restarts and new crashes until I notice them. Setting the list to the current known config changes means in general it won't restart but the Bundle-clearing means it won't crash no matter what. A question for you though: do you correctly apply new locale configurations or new screen rotation configurations in the example app? Just curious if you've plumbed that through some other way (perhaps there are core react-native events I need to educate myself on...) |
same issue on react-natvie-screens 2.15.1 everything works correctly but on 3.7.0 - app started to crash |
Also on 3.9.0 the app crash |
@anija did you use one of the proposed fixes from this issue here? We did apply the fix suggested in the readme and no longer have android crashes out there. None (related to this bug). |
For anyone coming here from Google: Fix for the crash 👉 #17 (comment) The problem is explained both in the installation steps in and in the |
Hi,
at least in release builds I'm getting crashes when restoring app from background, but not always. I replaced
ReactActivity
withReactFragmentActivity
.react-native: 0.57.0
The text was updated successfully, but these errors were encountered: