0

I'm developing an android java application,

I'm stuck on a point of how to run a function in the background even if the app is closed.

My goal is to get the user location every 30 minutes.

Thank you.

Rima
  • 19
  • 3
  • FWIW, starting from android 10, there are more restrictions on accessing location in background. – Shivam Pokhriyal Mar 17 '20 at 06:18
  • You need a foreground service. This will ensure that Android system wont kill your service even if it is in background. Inside the service you can write your logic to fetch the location info – Ezio Mar 17 '20 at 06:21
  • Does this answer your question? [How to make an android app to always run in background?](https://stackoverflow.com/questions/34573109/how-to-make-an-android-app-to-always-run-in-background) – D buiss Mar 17 '20 at 06:31

2 Answers2

0

You can either use JobIntentService or WorkManager for running the task periodically.

JobIntentService

WorkManager Periodically

Ravi
  • 2,277
  • 3
  • 22
  • 37
0

You can use Service to get user location while the application is in the background.

And for further implementation you can refer below link:-

https://stackoverflow.com/a/8830135/11625897

Ankit Lathiya
  • 199
  • 1
  • 12