简体   繁体   English

在react-native中运行android后台任务

[英]run android background task in react-native

I want to create an ability in my react-native android app to send my user geolocation to the server for each period of time, even if he closed the app! 我想在我react-native android应用程序中创建一个功能,以便在每个时间段内将我的用户geolocation发送到服务器,即使他关闭了该应用程序也是如此! so probably it means i have to run some thing like a task for run on Os(android) from a NativeModule .(and you can recommend better solution if you have). 所以可能这意味着我必须从NativeModule运行某些事情,例如在OS(android)上运行的任务(如果有的话,您可以推荐更好的解决方案)。

but after spending many time on searching i have not found any example of creating a job or process which can keep running if app closed. 但是在花费大量时间进行搜索之后,我还没有找到任何创建工作或流程的示例,如果应用程序关闭,该工作或流程可以保持运行。 can any body give some clue about it ? 任何机构都可以提供一些线索吗?

Update: i can ask my question like this to: how can i run a process for keep execute if app has closed in react native? 更新:我可以这样问我的问题:如果应用程序已在React Native中关闭,我如何运行一个进程以保持执行?

For Android, there's this option: https://facebook.github.io/react-native/docs/headless-js-android . 对于Android,有以下选项: https : //facebook.github.io/react-native/docs/headless-js-android You could also just write native code to do what you to do. 您也可以编写本机代码来完成您的工作。 Refer to the Android guides on how to implement services. 有关如何实施服务的信息,请参阅Android指南。

If you only want to use this for location purposes, I would suggest you to use a library, https://github.com/mauron85/react-native-background-geolocation 如果您只想将此用于位置目的,我建议您使用一个库, https://github.com/mauron85/react-native-background-geolocation

I have used it in few apps, it gets the job done, And it will save you the time to write a native module for both android as well as ios. 我已经在少数几个应用程序中使用过它,它可以完成工作,并且可以节省您为Android和ios编写本机模块的时间。 Or if you don't want to use it for location purpose, you can use headless js , 或者,如果您不想将其用于定位,则可以使用headless js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Android 的 Expo React-native:如何在后台运行应用程序? - Expo React-native using Android: How to run app in background? 运行react-native run-android时,任务&#39;:react-native-icons:compileReleaseAidl&#39;的执行失败 - Execution failed for task ':react-native-icons:compileReleaseAidl' when running react-native run-android React-Native 无头任务不适用于 android - React-Native Headless task not working on android &gt; 任务 :app:checkDebugAarMetadata 在运行 react-native run-android 时失败 - > Task :app:checkDebugAarMetadata FAILED when run react-native run-android 当我尝试运行 npx react-native run-android 时,任务:应用程序:mergeDebugAssets 失败 - Task :app:mergeDebugAssets FAILED when I try to run npx react-native run-android Android &lt;5上的react-native run-android - react-native run-android on Android < 5 后台的React-Native Geolocation API(android) - React-Native Geolocation API on Background (android) react-native android 上的后台服务 - Background service on react-native android React-Native后台进程(android)处理? - React-native background process(android) handling? 如果没有react-native,是否有可能在Android和/或iOS的后台任务中收集地理位置信息? - Is it possible without react-native to gather geolocation information in a background task for Android and/or iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM