Start two services in foreground?

a 夏天 提交于 2019-11-29 12:03:39
Trinimon

There are several aspects to consider.

  1. First of all: if you have two services in foreground, you have to have two notifications as well. This is considered as a security feature (check for instance this post). Having two icons in the status bar for one app might be quite confusing to the user and is IMHO reason enough to drop this idea.
  2. As stated in the comments: even if starting in foreground, a service might be destroyed anyway. Just keep this in mind. However, in my experience this happens rather rarely, almost never - except with ...
  3. ... devices that are shipped with pre-installed start managers or energy savers (many Huawei devices for instance). If your app is not configured appropriately your services will be killed several seconds/minutes after the screen turns off - or it will not automatically be started after reboot.

So, as always it depends on what exact you want to achieve ;) But to me it looks like as if you could simply implement two threads in one sticky service - I can't any see disadvantages here.

If your app gets inactivated by any kind of start manager, crash, or force close, your users might have to start the app again (see this post including app states).

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!