startService() 一旦被创建 调用着无关 没法使用service里面的方法
bindService () 把service 与调用者绑定 ,如果调用者被销毁,service会销毁
bindService() 我们可以使用service里面的方法
bindService(). 让activity能够访问到 service里面的方法
构建一个intent对象,
Intent service = newIntent(this,MyService.class);
通过bindService的方法去启动一个服务,
bindService(intent, new MyConn(),BIND_AUTO_CREATE);
ServiceConnection对象(重写onServiceConnected和OnServiceDisconnected方法) 和BIND_AUTO_CREATE.
privateclass myconn implements ServiceConnection
{
publicvoid onServiceConnected(ComponentName name, IBinder service) {
//TODO Auto-generated method stub
//可以通过IBinder的对象去使用service里面的方法
}
publicvoid onServiceDisconnected(ComponentName name) {
//TODO Auto-generated method stub
}
}
bindService () 把service 与调用者绑定 ,如果调用者被销毁,service会销毁
bindService() 我们可以使用service里面的方法
bindService(). 让activity能够访问到 service里面的方法
构建一个intent对象,
Intent service = newIntent(this,MyService.class);
通过bindService的方法去启动一个服务,
bindService(intent, new MyConn(),BIND_AUTO_CREATE);
ServiceConnection对象(重写onServiceConnected和OnServiceDisconnected方法) 和BIND_AUTO_CREATE.
privateclass myconn implements ServiceConnection
{
publicvoid onServiceConnected(ComponentName name, IBinder service) {
//TODO Auto-generated method stub
//可以通过IBinder的对象去使用service里面的方法
}
publicvoid onServiceDisconnected(ComponentName name) {
//TODO Auto-generated method stub
}
}