如何绑定这项服务的Andr​​oid?绑定、Andr、oid

由网友(浮梦一生)分享简介:这是在code在我的活动。启动一个意图,然后一个连接,对吧?This is the code in my Activity. Initiate an Intent, then a Connection, right?hello_service = new Intent(this, HelloService.clas...

这是在code在我的活动。启动一个意图,然后一个连接,对吧?

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) {

        }
    };

谁能告诉我是什么code我投入的 onServiceConnected 和 onServiceDisconnected

我只想要一个基本的连接,使我的活动服务可以互相交谈。

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/

推荐答案

我想指出的是,如果你遵循由谷歌提供的服务的例子那么你的服务将导致内存泄漏,看到这样的CHAPS对如何做到这一点优秀的帖子正常(与投票相关的谷歌错误)

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

阅读全文

相关推荐

最新文章