title: Intent Service running properly on android 9 when app is in background
body: <p>I have an Intent service &amp; a BroadcastReceiver.</p>
  <p>As per background limitation on Android Oreo &amp; above, the background applications(when an application is not foreground ) cannot use the started service. When you call <strong>startService</strong>() method from the background applications simply through the IllegalStateException.</p>
  <p>But In my case, My intent service is running properly even when the app is in the background.
  I am using ADB cmd to trigger broadcast.</p>
  <p>Please correct where I am missing.</p>
  <pre><code>adb shell am broadcast -a android.intent.action.TEST --es maxCountValue 10 -n com.example.servicedemo/.MyReceiver
  enter code here
  </code></pre>
  <p>BroadcastReceiver class</p>
  <pre><code>class MyReceiver : BroadcastReceiver() {
      override fun onReceive(context: Context?, intent: Intent?) {
          Toast.makeText(context, &quot;CompleteReceiver&quot;, Toast.LENGTH_LONG).show()
          if (intent!!.action.equals(&quot;android.intent.action.TEST&quot;)) {
              val mIntent = Intent(context, MyIntentService::class.java).apply {
                  Log.v(&quot;MyIntentService&quot;, intent.data.toString())
                  this.putExtra(&quot;maxCountValue&quot;, 100)
              }
              context?.startService(mIntent)
          }
      }
  }
  </code></pre>
  <p>Intent Service</p>
  <pre><code>private const val SERVICE_NAME = &quot;MyIntentService&quot;
  
  class MyIntentService : IntentService(SERVICE_NAME) {
      private val handler = Handler()
  
      override fun onCreate() {
          super.onCreate()
          showToast(&quot;Job Execution Started&quot;)
      }
  
      override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
          showToast(&quot;Job Execution onStartCommand&quot;)
          return super.onStartCommand(intent, flags, startId)
      }
  
      override fun onDestroy() {
          super.onDestroy()
          showToast(&quot;Job Execution onDestroy&quot;)
      }
      override fun onHandleIntent(intent: Intent?) {
          val maxCount = intent!!.getIntExtra(&quot;maxCountValue&quot;, -1)
  
          for (i in 0 until maxCount) {
              Log.d(SERVICE_NAME, &quot;onHandleWork: The number is: $i&quot;)
              try {
                  Thread.sleep(100)
              } catch (e: InterruptedException) {
                  Log.d(SERVICE_NAME, &quot;Exception: &quot;)
                  e.printStackTrace()
              }
          }
      }
  
      private fun showToast(msg: String) {
          handler.post {
              Toast.makeText(this@MyIntentService, msg, Toast.LENGTH_LONG).show()
          }
      }
  }
  </code></pre>
  <p>Manifest :</p>
  <pre><code>&lt;service android:name=&quot;.MyIntentService&quot;/&gt;
  
          &lt;receiver android:name=&quot;.MyReceiver&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.TEST&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  </code></pre>