Hello I have a little chat application, which bind to my service who creates a tcp/ip connection with my server.
I use aidl btw.
My problem is that I don’t know to handle screen orientation especially on destroy method.
I would like that my service to be online all the time and I don’t want to stop it when application destroys.
For now I have on “onDestroy” method unbindService(conn) to resolve the “leaked connection problem”.
After activity is destroyed when is recreated it freeze.
Thank you, and here are some code snippets.
serviceIntent = new Intent(getApplicationContext(),ChatService.class);
boolean result = bindService(serviceIntent, conn,Context.BIND_AUTO_CREATE);
startService(new Intent(getApplicationContext(),ChatService.class));
Log.d(TAG, "Service binded");
@Override
protected void onDestroy() {
Log.d(TAG, "ON DESTROY");
unbindService(conn);
super.onDestroy();
}
Service does not have UIs, therefore you may say that this does not depends on your service, but your activity. Return
START_STICKYinonStartCommand()which tells you that it has to be running even when you unbind from it, basically you can bind/unbind any time to the persistent (not persistent until android OS decides to kill it) running service.In your activity override
onConfigurationChange()method and do nothing in it, then in your manifest useandroid:configChanges="orientation".