High priority Android services

前端 未结 2 952
悲&欢浪女
悲&欢浪女 2021-01-13 20:51

I\'m looking into implementing an over-Bluetooth video streaming service for Android.

How can I ensure that:

  • the service runs with a high priority? I\'
2条回答
  •  清酒与你
    2021-01-13 21:35

    There are two important things you need to do to make sure your service keeps running:

    1. Make sure you call startService() instead of (or in addition to) binding. This will make sure that the service continues running, even if the Activity that created it is killed.

    2. Use startForegroud() to run the service in the foreground, so that Android won't reclaim it when memory is needed. It requires that you also create a Notification that gets published when the service actually starts, putting an icon in the notification area and letting the user know your service is still running.

    For more information:

    http://developer.android.com/reference/android/app/Service.html http://developer.android.com/guide/topics/fundamentals/bound-services.html

提交回复
热议问题