Issues after android system closes application
See original GitHub issueHi Chris! This is an amazing library and has helped considerably with a RN project I am working on. Thank you with putting it together and also for your contribution to other cross-platform development ecosystems!
I’ve been tracking a bug for several weeks and was hoping you could shed some insight on how to address an issue that I’m encountering. Also, I think this may apply to the native implementation, so I’m happy to re-post in https://github.com/transistorsoft/transistor-background-fetch if needed.
==========
Plugin version: 2.4.5
Platform: Android
OS version: 9.0, 8.0, 7.1
Device manufacturer / model: Essential Phone, HTC 10, Nextbit Robin
React Native version (react-native -v
): 0.57.8
Plugin config:
minimumFetchInterval: 15,
stopOnTerminate: false,
startOnBoot: true,
forceReload: true,
Expected Behavior
If app is killed by android system. React-native-background-fetch should restart app (and MainActivity) just like when user swipes out application.
Actual Behavior
When the app is killed by system, background fetch still runs at fixed interval (and logs “Background Fetch event received”), but app is assigned a new PID when it is relaunched by background-fetch, and doesn’t seem to initialize RN app properly since no JS will run, and the background fetch seems to time out printing “onStopJob” after a while.
IE: background fetch stops running properly after app is killed by system and after killed notifications/actions won’t work until user opens app manually which triggers a reset.
After this ‘crash’, the next time I bring the app to foreground, it initializes, then minimizes immediately as if being force reloaded by react-native-background-fetch, but it doesn’t print “MainActivity is inactive” and “Forcing MainActivity reload” like it does when app is reset in background after being swiped out by user. Ideally, it would be able to restart the MainActivity in the same way without me clicking on the app.
It starts working again properly after bringing app to foreground manually,
Steps to Reproduce
- Wait all day w/o bringing app to foreground until app is killed by system and I stop receiving the notifications that should be scheduled by my background task
- Inconsistent behavior but seems to be an issue for some phones more than others (some phone 1-2 times per day) some phones can’t reproduce.
Context
I’m trying to implement background tasks that persist after app is killed by system
Debug logs
Normal logs:
03-25 13:29:32.841 15313 15313 D TSBackgroundFetch: - Background Fetch event received 03-25 13:29:32.841 15313 15332 D ReactNativeJS:: - a bunch of stuff I’m printing 03-25 13:29:32.841 15313 15313 D TSBackgroundFetch: - finish 03-25 13:29:32.841 15313 15313 D TSBackgroundFetch: - jobFinished
After being closed by system (assigns new PID):
03-27 09:52:19.314 17419 17419 D TSBackgroundFetch: - Background Fetch event received 03-27 09:52:24.203 17419 17419 D TSBackgroundFetch: - onStopJob 03-27 09:52:54.841 17419 17419 D TSBackgroundFetch: - Background Fetch event received 03-27 10:02:54.862 17419 17419 D TSBackgroundFetch: - onStopJob 03-27 10:03:59.864 17419 17419 D TSBackgroundFetch: - Background Fetch event received 03-27 10:07:54.836 17419 17419 D TSBackgroundFetch: - onStopJob 03-27 10:10:39.369 17419 17419 D TSBackgroundFetch: - Background Fetch event received 03-27 10:16:44.769 17419 17419 D TSBackgroundFetch: - onStopJob 03-27 10:20:44.823 17419 17419 D TSBackgroundFetch: - Background Fetch event received
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top GitHub Comments
@mason-parachute I was doing some work today on transistor-background-fetch, #154, #157. I’ll be having at look at your PR
#4
there, tomorrow.It doesn’t work with current version of master, only my fork. I’m using the following config:
minimumFetchInterval: 15, stopOnTerminate: false, startOnBoot: true, enableHeadless: true