Reputation: 3969
In my project android service is communication with serial device and it is being started when BOOT_COMPLETED broadcast is received. Occasionally I want to bind to the service for persistent connection. After unbind the service seems to restart, which is not very desirable when communication with serial device.
In Service:
@Override
public IBinder onBind(Intent intent)
{
Log.d(TAG, "onBind");
return messenger.getBinder();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
...
return START_STICKY;
}
In Activity:
@Override
protected void onStart()
{
super.onStart();
bindService(new Intent(this, BMWiService.class), serviceConnection, Context.BIND_AUTO_CREATE);
}
@Override
protected void onStop()
{
super.onStop();
if (serviceBound)
{
unbindService(serviceConnection);
serviceBound = false;
}
}
Upvotes: 0
Views: 617