0

Could somone explain to me why after calling unbindService i'm still able to communicate with the service ?

The flow:

bindService(new Intent(IService.class.getName()), conn, Context.BIND_AUTO_CREATE)
...
mService = IService.Stub.asInterface(service);
...
writeToOutput("Droping bombs from: " + mService.getPid());
...
unbindService(mCurConnection);  
... 
writeToOutput("Droping bombs from: " + mService.getPid()); // no exception - still returns good values
...
LazyBones
  • 107
  • 2
  • 10

1 Answers1

1

Perhaps the service is still working on a task.

In the google documentation it states that calling unbindService(Connection) simply allows the service to stop at any time. It does not mention that it is a hard stop or a force stop.

From google doc: "Disconnect from an application service. You will no longer receive calls as the service is restarted, and the service is now allowed to stop at any time."

Another possibility is that you may have another activity binding to the service and so long as you have at least one bound interface the service stays active.

If you would like to post more details about what you are doing, I can probably provide a better solution.

Thanks

Birdnado
  • 156
  • 1
  • 7
  • I'm trying to replicate the RemoteService from ApiDemos. The problem is that i dont want to end the service but close connection for the user. I know that there are other ways to do that, but i was just wondering why it still allows communication after i have told the connection to end. – LazyBones Jul 25 '12 at 14:37
  • It probably is still working on a task and so allowing communication. As a client of the service though, you should have your code structured in such a way that after you call disconnect, you no longer communicate with the service until you explicitly connect or reconnect. – Birdnado Nov 17 '14 at 19:31