How to make an application run continuously in android?

后端 未结 2 2007
难免孤独
难免孤独 2021-01-13 09:54

I am creating an application which sends the location information to the server. But when the back or home button is clicked the application is stopped. Is there a way to ma

相关标签:
2条回答
  • 2021-01-13 10:28

    Use a background Service. Services are application components which can run in the background without user interaction. A good tutorial on Service in android is from this.

    You probably want to start the service on launch of your Activity, or you can register for system broadcasts like BOOT_COMPLETE to keep your service running from boot up.

    However, keeping your service running throughout without user knowledge is a bad idea, and drains battery also. You probably want to wake up the service using AlarmManager, do processing, schedule next restart, and exit.

    0 讨论(0)
  • 2021-01-13 10:44

    You need to run a Service class for your own application.

    Refer docs for more information.

    0 讨论(0)
提交回复
热议问题