Local service or remote service?

前端 未结 3 1151
北荒
北荒 2021-02-06 12:38

I have a background Service which must run permanently. The service just has to interact with my Activity.

  1. How to i check on activity resume if the service is

3条回答
  •  伪装坚强ぢ
    2021-02-06 13:18

    I have a background service which must run permanently.

    This is not possible. The user or Android will kill off your service at some point. Please reconsider your architecture.

    How to i check on activity resume if the service is still running?

    Generally, you don't.

    Is there a better possibility than a static variable in the service class?

    That will not work if the user or Android kills off your service.

    Is it of advantage to use a remote service in a separate process(to extend service life time) so that when the activity process gets killed the service is still alive?

    A remote service has nothing to do with whether the service runs after activities are destroyed. If you call startService(), the service will run, independent of any activities, until:

    • you call stopService() from an activity
    • the service calls stopSelf()
    • Android terminates the service
    • the user terminates the service via the Settings application
    • the user terminates the service via a "task killer" (Android 2.1 and earlier, at least)

提交回复
热议问题