Application get user location in the background


#1

Hello all, with NativeScript, I can make an application that is allowed to take the location of the person every 5 minutes to send a server and work in the background (continue to send information to a if the application is closed)

I was recommended by

Does this work if the app is closed? Is there an example?

Do you know any other options?

Thank you


#2

I wrote up a little something a couple months back about calling to Android’s native API to use its background services. Using IntentServices with BroadcastReceivers is the natural way in Android to make an application do work even when it is not in the foreground.

{NS} Workers != Android Background Services

You could use the former inside methods of the latter, that will offload method calls to a non-main thread when the scheduled service is triggered, but will only make a real difference if the service kicks off while the application is open, since a closed application does not care much about threads when performing as simple an operation as fetching GPS location.

And the {NS} Workers are simply, as mentioned above, new Runtime instances, with new and pristine JavaScript contexts where things can happen independently of work on the main thread, while the app is open.

Hope the above clears up the confusion


#3

Good afternoon thanks a lot for the information and the clarification, basically the best way to take the location with a service is to use the example described in this article?

Try to understand it and see how I can adapt it to what I need, since I’m just trying to start with NativeScript, but I wanted to validate first if I really could do what I need.

(Sorry for the language but it is a translation)

Thank you very much


#4

Good afternoon, reviewing the example of the article “BroadcastReceiver” of point three, This information should be placed in a new file? Or where to place that information. Thank you


#5

Hello pacear10, have you made everything working?
I stumble upon your thread as i was hoping to find answers to the exact same problem you’re having.


#6

I think this is outdated for tns 3
Do you have a working sample where i can see it?

Thank you for the guide


#7

Hello, I did not find a solution to the issue and I gave up.