title: Android background service with no UI is not answering
body: <p>I try to create a background service with no user interface and I created it with <code>BroadcastReceiver</code> and added my necessary things in the manifest file. Then I configure <a href="https://www.programmersought.com/article/5560819605/" rel="nofollow noreferrer">Nothing</a> as written in the link. I'm testing on an Android emulator, when I execute my app nothing happen and the service is not starting. Where is my problem?</p>
  <p>Here is my manifest</p>
  <pre><code>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.test.myapplication22&quot;&gt;
  
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
      &lt;uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot; /&gt;
      
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/Theme.MyApplication22&quot;&gt;
      
          &lt;service android:name=&quot;.MyService&quot; /&gt;
      
      
          &lt;receiver
              android:name=&quot;.StartReceiver&quot;
              android:enabled=&quot;true&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p>Here is my BroadcastReceiver</p>
  <pre><code>override fun onReceive(context: Context, intent: Intent) {
      Log.i(&quot;MYSERVICE&quot;,&quot;override fun onReceive(context: Context, intent: Intent)&quot;)
      if (intent.action == Intent.ACTION_BOOT_COMPLETED ) {
          Intent(context, MyService::class.java).also {
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
                  context.startService(it)
  
                  return
              }
              context.startService(it)
          }
      }
  }
  </code></pre>
  <p>Here is my Service</p>
  <pre><code>class MyService : Service() {
      
      override fun onBind(intent: Intent): IBinder? {
          return null
      }
  
      override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
          if (intent != null) {
              println(&quot;MYSERVICE STARTED AUTOMATICALLY&quot;)
          }
          return START_STICKY
      }
  
      override fun onCreate() {
          super.onCreate()
          println(&quot;MYSERVICE override fun onCreate() {&quot;)
  
      }
  
      override fun onDestroy() {
          super.onDestroy()
          println(&quot;MYSERVICE override fun onDestroy() {&quot;)
  
      }
  }
  </code></pre>