title: The difference between Bound Services and Threads
body: <p>I'm studying Android services because I heard that this is the android recommendation to perform background tasks.</p>
  
  <p>I want to interact with that service, so this is the reason that I've chosen Bound Services (btw, I don't want to run that service indefinitely).</p>
  
  <p>The question is: Why should I complicate myself using the IBinder interface and call my methods via this callback <a href="https://developer.android.com/guide/components/bound-services.html#Binder" rel="nofollow noreferrer">see official docs</a> </p>
  
  <p><code>@Override 
  public void onServiceConnected(ComponentName className, IBinder service){}</code> </p>
  
  <p>when I can simply create my custom service? For example, if I want to play some background music in a single Activity I can create this custom (and simple) service:</p>
  
  <pre><code>public class MyOwnService {
      MediaPlayer mp;
      MainActivity ma;
  
      public MyOwnService(MainActivity mainActivity) {
          mp = MediaPlayer.create(mainActivity, R.raw.badinerie);
          ma = mainActivity;
      }
  
      public void play(){
          new Thread(new Runnable() {
              @Override
              public void run() {
                  mp = MediaPlayer.create(ma, R.raw.badinerie);
                  mp.start();
  
              }
          }).start();
      }
  
      public void pause(){
           mp.pause();
      }
  
      public void stop(){
          mp.stop();
          mp.release();
      }
  }
  </code></pre>
  
  <p>and call my service in a simplest way like this</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      MyOwnService myOwnService;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myOwnService = new MyOwnService(this);
      }
  
      public void play(View view) {
           myOwnService.play();
      }
  
      public void pause(View view) {
          myOwnService.pause();
      }
  
      public void stop(View view) {
          myOwnService.stop();
      }
  }
  </code></pre>