J Doe
J Doe

Reputation: 1

App monitor location on background service

I would like to make an app that always works in the background (from boot up), which sends GPS coordinates to a server. This app should ALWAYS be active and should never close. Should I use the services? I would like to use UDP sockets to send coordinates but I accept alternatives. I would also like to avoid using the google API.

Thanks a lot :)

Upvotes: 0

Views: 667

Answers (1)

AJAY PRAKASH
AJAY PRAKASH

Reputation: 1110

If your app need to run in the background , you need Service and you need to make it a foreground service which means you need to show a notification to the user as long as your application is running.

To open app on device boot, from Android O, its not allowed. You will get an IllegalStateException. The main reason for this is to prevent exactly what you are trying to achieve.

Its not good to keep running an app in the background and its especially bad to keep tracking users GPS coordinates and send it to the server. Because it will drain the battery very soon.

However it is possible to keep a foreground service running which can take the GPS coordinates and send it to the server. But for that user has to open your App first.

Please refer to https://developer.android.com/about/versions/oreo/background#services

Other alternative is to use JobIntentService which will schedule your tasks in smart ways to avoid draining users battery and data.

Regarding UDP sockets , it depends on your backend.

Upvotes: 1

Related Questions