I have an Activity, and I've bound a service to it.
In the onServiceConnected method, I have I get the object of the service from which I directly access the service method. That is, I have a method in the service which is accessed from the activity using the object received from the onserviceconnected method.
Would this cause any memory leaks? Or this is the wrong method of accessing a service? If开发者_高级运维 it's wrong, how can I fix it?
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
mBoundService = ((RadioPlayerService.RadioBinder)service).getService();
mBoundService.StartStream(mMessenger);
}
public void onServiceDisconnected(ComponentName className) {
mBoundService = null;
}
};
That looks correct!
As long as you're not trying to access the service when it isn't bound (or when it's not null, in this case) it will work correctly.
精彩评论