title: Android service recreated when main activity destroyed
body: <p>I have a problem with android service,
  When i close the app the main activity closed and the service is recreated - oncreated method
  call automatic and onstart also called automatic - and all the state is gone.</p>
  
  <p>This is my activity code</p>
  
  <pre><code>   public class ServicesDemo extends Activity implements OnClickListener
  {
      private static final String TAG = "ServicesDemo";
      Button buttonStart, buttonStop;
  
      @Override
      public void onCreate(Bundle savedInstanceState)
      {
          if (savedInstanceState != null)
          {
              Log.d(TAG, "ServicesDemo:onCreate WITH savedInstanceState)");
          }
          Log.d(TAG, "ServicesDemo:onCreate");
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          buttonStart = (Button) findViewById(R.id.buttonStart);
          buttonStop = (Button) findViewById(R.id.buttonStop);
  
          buttonStart.setOnClickListener(this);
          buttonStop.setOnClickListener(this);
      }
  
      public void onClick(View src)
      {
          switch (src.getId())
          {
          case R.id.buttonStart: 
              Log.d(TAG, "onClick: starting srvice");
              startService(new Intent(this, MyService.class));
              break;
          case R.id.buttonStop:
              // Log.d(TAG, "onClick: stopping srvice");
  
               stopService(new Intent(this, MyService.class));
              break;
          }
      }
  }
  </code></pre>
  
  <p>This is the service Code:</p>
  
  <pre><code>public class MyService extends Service
  {
      private static final String TAG = "ServicesDemo";
      private static MyThread t = new MyThread();
      static int yy = 90;
  
      @Override
      public IBinder onBind(Intent intent)
      {
          return null;
      }
  
      @Override
      public void onCreate()
      {
          Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
          Log.d(TAG, "onCreate");
          // MockGPSLocationModel.getInstance().Counter++;
  
          // Log.d(TAG, "MockGPSLocationModel.getInstance().Counter :: " +
          // MockGPSLocationModel.getInstance().Counter);
          // MockGPSLocationModel.getInstance().Counter++;
      }
  
      static public class MyThread extends Thread
      {
          MediaPlayer player;
          public Context ctx;
  
          @Override
          public void run()
          {
              try
              {
                  for (int i = 0; i &lt; 100; i++)
                  {
                      Log.i(TAG, "lOOP - " + i);
                      Thread.sleep(2000);
                  }
                  player = MediaPlayer.create(ctx, R.raw.braincandy);
                  player.setLooping(false); // Set looping
                  player.start();
              }
              catch (Exception e)
              {
                  Log.e(TAG, e.toString());
  
              }
              finally
              {
  
              }
          }
      }
  
      @Override
      public void onDestroy()
      {
          Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
          Log.d(TAG, "onDestroy");
          // player.stop();
      }
  
      @Override
      public void onStart(Intent intent, int startid)
      {
          Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
          Log.d(TAG, "onStart");
  
          t.ctx = this;
          t.start();
  
          // player.start();
      }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;application
          android:icon="@drawable/icon"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".ServicesDemo"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name=".MyService"
              android:enabled="true" /&gt;
      &lt;/application&gt;
  
      &lt;uses-sdk android:minSdkVersion="3" /&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Please help.
  I stuck with that 3 days.</p>
  
  <p>Thx, 
  Alon</p>