首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

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

2012-08-24 
Android BroadcastReceiver无法bindservice的解释与解决办法引用If this BroadcastReceiver was launched

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进行管理

热点排行