如何在 Android 中绑定此服务? [英] How do I bind this service in Android?
问题描述
这是我的Activity
中的代码.发起一个意图,然后是一个联系,对吧?
This is the code in my Activity
. Initiate an Intent, then a Connection, right?
hello_service = new Intent(this, HelloService.class);
hello_service_conn = new HelloServiceConnection();
bindService( hello_service, hello_service_conn, Context.BIND_AUTO_CREATE);
但我的问题是……连接内部有什么?
But my question is...what goes inside the Connection?
class HelloServiceConnection implements ServiceConnection {
public void onServiceConnected(ComponentName className,IBinder boundService ) {
}
public void onServiceDisconnected(ComponentName className) {
}
};
谁能告诉我我在 onServiceConnected 和 onServiceDisconnected 中放入了什么代码?
Can someone tell me what code I put into onServiceConnected and onServiceDisconnected?
我只需要一个基本的连接,以便我的 Activity
和 Service
可以相互通信.
I just want a basic connection so that my Activity
and Service
can talk to each other.
我找到了一个很好的教程,我实际上可以关闭这个问题,除非有人想回答.http://www.androidcompetencycenter.com/2009/01/basics-of-android-part-iii-android-services/
I found a good tutorial, and I can actually close this question, unless someone wants to answer. http://www.androidcompetencycenter.com/2009/01/basics-of-android-part-iii-android-services/
推荐答案
我想指出的是,如果您按照 google 提供的服务示例进行操作,那么您的服务会泄漏内存,请参阅此 chaps 优秀帖子,了解如何操作正确(并为相关的 Google 错误投票)
I would like to point out that if you follow the service examples provided by google then your service will leak memory, see this chaps excellent post on how to do it properly (and vote for the related Google bug)
http://www.ozdroid.com/#!BLOG/2010/12/19/How_to_make_a_local_Service_and_bind_to_it_in_Android
这篇关于如何在 Android 中绑定此服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!