title: How to pass music Service from one Activity to another
body: <p>I'm starting my Music Service in my Main Activity where I display a list of songs. On clicking a song, it takes me to another activity where I do the basic controls. How do I continue with this same service in my second class?</p>
  <p>Main Activity:</p>
  <pre><code>open class MainActivity : AppCompatActivity() {
  private var musicSrv: MusicService? = null
  private var playIntent: Intent? = null
  private var musicBound = false
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
  }
  
  override fun onStart() {
      super.onStart()
      if (playIntent == null) {
          playIntent = Intent(this, MusicService::class.java)
          bindService(playIntent, musicConnection, Context.BIND_AUTO_CREATE)
          startService(playIntent)
      }
  }
  
  override fun onDestroy() {
      stopService(playIntent)
      musicSrv = null
      super.onDestroy()
  }
  
  fun songPicked(view: View) {
      musicSrv!!.setSong(view.tag.toString().toInt())
      musicSrv!!.playSong()
      val intent = Intent(this@MainActivity, SmartPlayerActivity::class.java)
      intent.putExtra(&quot;title&quot;, songList[view.tag.toString().toInt()].title)
      intent.putExtra(&quot;artist&quot;, songList[view.tag.toString().toInt()].artist)
      intent.putExtra(&quot;duration&quot;, songList[view.tag.toString().toInt()].seconds)
      startActivity(intent)
  }
  
  private val musicConnection: ServiceConnection = object : ServiceConnection {
      override fun onServiceConnected(name: ComponentName, service: IBinder) {
          val binder = service as MusicBinder
          musicSrv = binder.service
          musicSrv!!.setList(songList)
          musicBound = true
      }
  
      override fun onServiceDisconnected(name: ComponentName) {
          musicBound = false
      }
  }
  }
  </code></pre>