Binding service by BroadcastReceiver

后端 未结 8 1228
春和景丽
春和景丽 2021-02-12 15:32

My Application uses a service that is started by a BOOT_COMPLETE BroadcastReceiver, in run i\'m getting an error

my code:

public class projet extends Br         


        
8条回答
  •  灰色年华
    2021-02-12 15:59

    Problem

    BroadcastReceivers are not allowed to be bound to a Service as the other answers here have indicated.

    Solution

    A simple solution I used is to forward the Intent received by the BroadcastReceiver to the service you originally wanted to bind to, then implement some code in that service's onStartCommand() method to handle it.

提交回复
热议问题