TIM*_*MEX 9 java service android android-intent android-activity
这是我的代码Activity.启动一个Intent,然后一个Connection,对吧?
hello_service = new Intent(this, HelloService.class);
hello_service_conn = new HelloServiceConnection();
bindService( hello_service, hello_service_conn, Context.BIND_AUTO_CREATE);
Run Code Online (Sandbox Code Playgroud)
但我的问题是......连接内部是什么?
class HelloServiceConnection implements ServiceConnection {
public void onServiceConnected(ComponentName className,IBinder boundService ) {
}
public void onServiceDisconnected(ComponentName className) {
}
};
Run Code Online (Sandbox Code Playgroud)
有人能告诉我在ServiceConnected和onServiceDisconnected上添加了哪些代码?
我只想要一个基本的连接,以便我Activity和Service他人可以互相交谈.
编辑:我找到了一个很好的教程,我实际上可以关闭这个问题,除非有人想回答.http://www.androidcompetencycenter.com/2009/01/basics-of-android-part-iii-android-services/
Chr*_*s.D 16
我想指出,如果您按照谷歌提供的服务示例,那么您的服务将泄漏内存,请参阅此章如何正确地执行此操作(并投票支持相关的Google错误)
http://www.ozdroid.com/#!BLOG/2010/12/19/How_to_make_a_local_Service_and_bind_to_it_in_Android
小智 5
应该避免从活动绑定到服务,因为它会在活动配置发生变化时导致探测(例如,如果设备被轮换,活动将从头开始再次创建,并且必须重新创建绑定).
请参阅以下关于stackoverflow的帖子中Commonsware的评论
与来自服务的活动(LocalService)进行通信 - Android最佳实践
| 归档时间: |
|
| 查看次数: |
36019 次 |
| 最近记录: |