react-native-background-actions: Occasional Background task crash in production
My Sentry instance is catching occasional failures to start the background task.
https://sentry.ecoeats.uk/share/issue/7cf6f7ee88ee454ca3e73647693f83e3/
The issue appears to be that the buildNotification method constructs an Intent but the constructor returns null. I’m unable to replicate this issue in a dev environment.
notificationIntent = new Intent(context, context.getCurrentActivity().getClass());
Is the issue possibly that I’m attempting to start a task that is in the background already / the calling function is already in the background?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
Commits related to this issue
- Fix: Issue #61 React context was getting null — committed to raply-io/react-native-background-actions by ArsalImam 3 years ago
- fix: Fix #61 when React context was null — committed to Rapsssito/react-native-background-actions by ArsalImam 3 years ago
- chore(release): 2.6.1 [skip ci] ## [2.6.1](https://github.com/Rapsssito/react-native-background-actions/compare/v2.6.0...v2.6.1) (2021-06-09) ### Bug Fixes * Fix [#61](https://github.com/Rapsssito/... — committed to Rapsssito/react-native-background-actions by semantic-release-bot 3 years ago
The issue only appears sporadically in devices in the wild, so I’m afraid I can’t really do much to test it and get any decent results. If somebody else encounters this issue and knows why, let us know!
🎉 This issue has been resolved in version 2.6.1 🎉
The release is available on:
Your semantic-release bot 📦🚀
@Rapsssito I’ll working on it on later day. Maybe I could provide a reproduceble code
@stewartmcgown, thanks for the reproducible code! It looks like an error when trying to access the React context while it is initialized. I will try to fix it ASAP.
For a bit of extra context, I’ve been able to trigger this via two different situations - both to do with restarting the app.
a) CodePush.restartApp() will occasionally trigger this
b) Restarting via the AlarmManager will cause this error every time unless a delay is added to the BackgroundService.start(…) call. I discovered this when implementing a periodic hard restart for our Kiosk app to prevent memory leaks over several months of operation.
e.g. code like this will trigger the background actions crash when the app is reinitialised.
I’ve updated our call to background actions accordingly:
I’m seeing mostly the same bug:
currently only reported on an Huawei Mate 20 with Android 10 (SDK 29)
My code is a bit different though, as i start the background task when the app goes to background. It seems
getReactNativeHost().getReactInstanceManager().getCurrentReactContext()returns
nullin that case. I now adapted the code a bit to see if that improves the behaviour, i’ll come back to report if that is true.