-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 Android -- detachViewFromInstance() prevents Background Tasks if App is closed #16267
Comments
Seems to be a design issue. #15960
Other |
@vjeranc that's really unfortunate to hear. Albeit a personal fork of react-native, I'm happy to hear that you were able to develop a bypass. Could you please share how you managed to remove the unregistering logic so that I may apply the same patches and continue working and testing this too? |
@trevorwhealy Initial workaround is to have a background task that never ends (Promise that never resolves). Task can be terminated from native code explicitly. This will keep the JS bridge alive after activity is destroyed and calls to other JS tasks should work. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Good bot. Closing an issue that still exists! |
Any Idea? My app crash with a background task (or background job) if I kill it... |
@BlackStef yeah I'm not entirely sure that Headless JS is reliable/mature enough yet to say. I don't think it natively supports a true background service experience since it kills the listeners when the app is closed. It is great for a minimized app experience, but to be honest, that is not something I think most people consider being "in the background", hence the confusion. @facebook-github-bot please reopen this issue it does not appear to be stale any longer. |
Hi guys, I fixed this problem by following this tutorial: |
@gervasioaraujo this is really cool thanks for sharing ! |
I tried to register the Headless JS task in the index.js file after registering the component like: ` import App from './App'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App); const bgTask = async (data) => { AppRegistry.registerHeadlessTask("BGTask", () => bgTask); But, when the task registration is done inside any component, and the app is killed, then the react native application context is undefined, and no task is being called. ` export default class App extends Component { handleChange = (text) => { handlePress = () => { } render() { ` |
Heads up: we moved react-native-netinfo into its own repository, which should allow for making changes and fixes much faster. If you'd like to create the same issue there, please go for it! |
When the app is closed,
detachViewFromInstance
is invoked bydetachRootView
and from then on, all the native BroadcastReceivers are disabled, meaning that background functionality and services are not truly possible with closed applications.Background services are a major component of certain applications, and if the native Android behavior (the BroadcastReceivers) are severed as part of the application closing, then..
The headlessJS bridge is not useful if the "background service" only functions if the app is minimized, but not if it is truly closed.
ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
react-native info
Environment:
OS: macOS Sierra 10.12.3
Node: 8.5.0
Yarn: Not Found
npm: 5.3.0
Watchman: 4.9.0
Xcode: Xcode 8.3.3 Build version 8E3004b
Android Studio: 2.3 AI-162.4069837
Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.2 => 0.49.2
Target Platform: Android Emulator - Nexus_6_API_23
Expected Behavior
The behavior in background mode would be consistent with behavior when the app is truly closed.
Actual Behavior
Logs come from background mode, but no logs come from the closed app.
The text was updated successfully, but these errors were encountered: