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?

2 Answers 2

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,

Sign up to request clarification or add additional context in comments.

4 Comments

does this component keep working even if app has closed??
yes, on android...on ios it will work for foreground.
You'r right ... but i have a mad boss SEO who just want native module :) tnx man
You can mark my answer if it helped, Thanks..and for native module...you can just write a service in java and connect it via bridge. There are many tutorials for that. But with that you would need to use native code for ios too.
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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.