-3

I'm working on Android project that related to GPS I still new to android so I don't know a lot about it.

My project is an app where it calculates the distance between user location and a specified other location so if the distance is less than (X) say 1KM the app will send a notification to the user.[[I know how to calculate the distance between two locations]].

My problem is: how can I do this even if the user didn't open the app (I mean if there's anyway that I can make the app calculates the distance in the background while the app is closed).so I want the GPS feature works in the background.

Thanks in Advance.

Jamal Alkelani
  • 606
  • 7
  • 19

4 Answers4

0

You can use a service for background process.

For your question for getting location, you should try these links:

Best way to get user GPS location in background in Android

Get GPS location via a service in Android

0

My solution for this problem was simply :-

you can use Services for working in the background (when the Activity isn't showing)

check this : -Get GPS location via a service in Android

**if you want this service to run for ever, even if the app is closed/killed you can use broadcast receivers **

Jamal Alkelani
  • 606
  • 7
  • 19
-1

User services. They are simple to use and all you need.

Here is the documentation.

A service is another component of an android application (like activity). You need to define the service in manifest. After that you could start the device using startService (intent). If you need to take some info (communicate with one activity) you can use bindService instead of startService. (Also need to implement onBind).

Another solution is to sendData using a broadcast receiver. Or you can simple set a notification in service and use it.

petezurich
  • 9,280
  • 9
  • 43
  • 57
thmmy95
  • 361
  • 2
  • 18
-1

To get the app to run in the background, you'll need to learn about a service. Service is a service that causes applications to run in the background such as gps, notification and more ..

link: https://developer.android.com/reference/android/app/Service.html