`
forhope
  • 浏览: 360378 次
  • 性别: Icon_minigender_1
  • 来自: 帝都
社区版块
存档分类
最新评论

Android BroadcastReceiver无法bindservice的解释与解决办法

 
阅读更多
引用

If this BroadcastReceiver was launched through a <receiver> tag, then the object is no longer alive after returning from this function. This means you should not perform any operations that return a result to you asynchronously -- in particular, for interacting with services, you should use startService(Intent) instead of bindService(Intent, ServiceConnection, int). If you wish to interact with a service that is already running, you can use peekService(Context, Intent).

peekService
引用

Provide a binder to an already-running service. This method is synchronous and will not start the target service if it is not present, so it is safe to call from onReceive(Context, Intent).


在实际操作中,通过peekservice并不能获得已经通过startservice开启的service对象。但是可以采用ServiceManger的addservice方法来注册service,并通过getservice获得该service,注意,getservice之前该service并不会启动。由serviceManager进行管理
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics