Skip to content
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

Headless JS doesn't work when app is killed #22881

Closed
ritta-ibrahim opened this issue Jan 5, 2019 · 8 comments
Closed

Headless JS doesn't work when app is killed #22881

ritta-ibrahim opened this issue Jan 5, 2019 · 8 comments
Labels
Bug Resolution: Locked This issue was locked by the bot.

Comments

@ritta-ibrahim
Copy link

Environment

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz
Memory: 860.27 MB / 3.89 GB
Binaries:
Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.2.0.0 AI-181.5540.7.32.5056338
react: "16.6.3",
react-native: "0.57.8",

Description

I'm looking for a way to run task or service when the app is killed (not in background state), I tried to use Headless JS but it's working in foreground only, then I tried the JobScheduler but it doesn't seem work when app is killed.
My task is about fetching data from server and push notification in some conditions.
Any help please.

@dulmandakh
Copy link
Contributor

you cannot run anything when app is killed.

@saadkhan6670
Copy link

@RittaIbrahim did you get Headless running while app in background ?
can you share any code base for it.

@rpander93
Copy link

rpander93 commented Apr 25, 2019

Same issue here. I disagree with @dulmandakh that you cannot run anything.

After I kill the app, then send it a push notification, I can see in logcat that the app wakes up and Firebase handles the notification. I also want to let JS handle the notification. Then the app crashes because of the following: https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten/49846410#49846410.

Apparently, the background system changed in newer versions of Android and this has to be updated in RN.

@tpjoynt
Copy link

tpjoynt commented Jul 8, 2019

It seems like HeadlessJsTaskService needs to be updated to use Job / JobScheduler https://developer.android.com/reference/android/app/job/JobScheduler.html

@firofame
Copy link

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () =>
  console.log('bgMessaging: ', new Date()),
);

Headless works when the app is in the background but not when app is killed

@mkamals1989
Copy link

@RittaIbrahim Headless JS seamlessly works when the app is killed i.e even when it is not in background. I had to handle In-line reply for push notification in my android app and Headless JS was the perfect solution for it. The documentation is very neat provided by them and it doesn't. Try setting to the timeout to 0 sec or min as required by your task and that should work fine.

@divich
Copy link

divich commented Dec 13, 2019

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () =>
  console.log('bgMessaging: ', new Date()),
);

Headless works when the app is in the background but not when app is killed

The above code doesn't work.

@bimix
Copy link

bimix commented Jan 21, 2020

@RittaIbrahim Headless JS seamlessly works when the app is killed i.e even when it is not in background. I had to handle In-line reply for push notification in my android app and Headless JS was the perfect solution for it. The documentation is very neat provided by them and it doesn't. Try setting to the timeout to 0 sec or min as required by your task and that should work fine.
Neat? Seriously? The RN documentation for Headless JS is one of the worse I have come across.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests