Android Service run indefenitely

前端 未结 1 483
你的背包
你的背包 2021-01-07 12:54

I notice that applications like Skype use a service which basically runs 24x7, without getting killed at all. You cannot even manually kill it using task killers ( you can k

相关标签:
1条回答
  • 2021-01-07 13:22

    How is this implemented?

    Based on the Skype screenshots that show a Notification icon, then they are most likely using startForeground().

    I find that in Android 2.3, my service gets killed after running for sometime.

    That is perfectly normal.

    First, most Android applications do not really need a service that "basically runs 24x7". Users do not like such services, which is why task killers and the Running Services screen and the auto-kill logic in the OS exist. The only reason a service should be running "24x7" is if is delivering value every microsecond. VOIP clients, like Skype, will deliver value every microsecond, as they are waiting for incoming phone calls. Most Android applications do not meet this criterion.

    If your service is running constantly, but for a user-controlled period (e.g., a music player), startForeground() is a fine solution.

    Otherwise, I would rather that you find a way to eliminate the service that "basically runs 24x7", switching to a user-controllable polling system using AlarmManager, so your service is generally not in memory except when it is delivering value.

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