How to make the application work in android?

I am creating an application that sends location information to a server. But when the "Back" or "Home" button is pressed, the application stops. Is there a way to get the application to run in the background and send data to the server?

+5
source share
2 answers

Use the Background Service . Services are application components that can run in the background without user interaction. Good tutorial on ServiceAndroid from this .

You probably want to start the service when you start your own Activity, or you can register for system translations, such as BOOT_COMPLETEfor your service to work from boot.

However, your service runs without user knowledge - this is a bad idea, and it also drains the battery. You probably want to wake up the service with AlarmManager, perform processing, schedule the next restart, and exit.

+9
source

You need to run the service class for your own application.

See docs for more details .

+1
source

All Articles