Broadcastreceiver components are not allowed to bind to services in android

Broadcastreceiver的OnReceive()里面去绑定Service时会报:Broadcastreceiver components are not allowed to bind to services in android异常,这是因为

OnReceive的生命周期是很短的,receiver 可能不存在,并且receiver 可能会被killed。

解决办法:

context.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
改成
context.getApplicationContext.bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    原文作者:ltym2014
    原文地址: https://blog.csdn.net/ltym2014/article/details/51005678
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞