1

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! 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).

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?

Iman Salehi
  • 908
  • 2
  • 14
  • 34

2 Answers2

2

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

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. Or if you don't want to use it for location purpose, you can use headless js,

Sarmad Shah
  • 3,725
  • 1
  • 20
  • 42
1

For Android, there's this option: 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.

marhaupe
  • 267
  • 1
  • 3
  • 10
  • 1
    I know that services in Android work this way, yes. By reading through the article it becomes clear that you simply define a service and start it from your JS thread. So yes, I'm pretty certain it's the right way to approach your problem. – marhaupe Dec 23 '18 at 14:37