In my Android app, I call both startService
and bindService
:
Intent intent = new Intent(this, MyService.class);
ServiceConnection conn = new ServiceConnection() { ... }
startService(intent)
bindService(intent, conn, BIND_AUTO_CREATE);
Later, I attempt to both unbindService and
stopService`:
unbindService(conn);
stopService(intent);
However, I get an exception on the call to unbindService
. If I remove this call, the app seems to run properly through the stopService
call.
Am I doing something wrong? I thought a bindService
call had to be associated with an unbindService
call, and a startService
call had to be associated with a stopService
call. This doesn't seem to be the case here, though.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…