title: Activity rotation cause service to be killed
body: <p>I have a service which plays music and an activity which provides the GUI for interacting with the service.The activity opens on list item click(I have a list of recordings) and it binds the service(and create it) at onCreate() method. </p>
  
  <p>When onDestroy() is called, I unbind the service (this will destroy the service) - this should be OK since I do not want the service to run if the activity is exited, but the problem appear on orientation change because it re-creates the activity again and the service too(and the track is stopped and played again from the beginning when rotating the device).</p>
  
  <p>I know about some flags (orientationChange) that might be useful, but is not a good practice for me since I want a different layout on landscape. 
  Also I could make the music player service to run as long as my app runs, but isn't a good idea since the user may not want to open the player, but want just to record, so the player service isn't necessarily here.</p>
  
  <p>Here are some code snippets:</p>
  
  <pre><code>    @Override
      protected void onCreate(Bundle savedInstanceState) {
          LocalBroadcastManager.getInstance(this).registerReceiver(mLocalReceiver, new IntentFilter(PlayerBroadcastReceiver.ACTION_PLAYER_SERVICE_STARTED));
          setContentView(R.layout.media_player_screen);
          setVolumeControlStream(AudioManager.STREAM_MUSIC);
          AudioPlayerServiceBridge.getInstance().addCallback(this);
          AudioPlayerServiceBridge.getInstance().doBindService(this);
  
          init(savedInstanceState);       
          super.onCreate(savedInstanceState);
      }
  
  @Override
  protected void onDestroy() {
      LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalReceiver);
      mLocalReceiver.removeCallback();
      Log.d(AudioPlayerActivity.class.getName(), "onDestroy() -&gt; "+AudioPlayerActivity.class.getName());
      AudioPlayerServiceBridge.getInstance().doUnbindService(this);
      AudioPlayerServiceBridge.getInstance().removeCallback(this);
  
      super.onDestroy();
  }
  </code></pre>
  
  <p>and the service connection manager:</p>
  
  <pre><code>public void doBindService(Context context) {
      // Establish a connection with the service.  We use an explicit
      // class name because there is no reason to be able to let other
      // applications replace our component.
      if(!mIsBound){
          context.bindService(new Intent(context, 
                  AudioPlayerService.class), serviceConnection, Context.BIND_AUTO_CREATE);
          mIsBound = true;
      }
  }
  
  public void doUnbindService(Context context) {
      if (mIsBound) {
          // If we have received the service, and hence registered with
          // it, then now is the time to unregister.
          if (mServiceMessenger != null) {
              Message msg = Message.obtain(null, AudioPlayerService.MSG_UNREGISTER_CLIENT);
              msg.replyTo = mMessenger;
              mServiceMessenger.send(msg);
          }
  
          // Detach our existing connection.
          context.unbindService(serviceConnection);
          mIsBound = false;
      }
  }
  </code></pre>
  
  <p>Please show me if possible a good practice to handle this problem.</p>