这是我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);
但我的问题是...Connection里面应该放什么?
class HelloServiceConnection implements ServiceConnection {
public void onServiceConnected(ComponentName className,IBinder boundService ) {
}
public void onServiceDisconnected(ComponentName className) {
}
};
请问在onServiceConnected和onServiceDisconnected中我需要放置什么代码?
我只是想建立一种基本连接,这样我的Activity
和Service
可以相互通信。
编辑:我找到了一个好的教程,现在我可以关闭这个问题,除非有人想回答。 http://www.androidcompetencycenter.com/2009/01/basics-of-android-part-iii-android-services/