title: How to use TextToSpeech in an app without a View (and without a Title Bar)
body: <p>I'm trying to write an app that uses TextToSpeech to speak a brief message without interfering with what is displayed on the screen.</p>
  <p>MainActivity.kt reads as follows:</p>
  <pre><code>package com.example.nearbyplaces
  
  import android.os.Bundle
  import android.speech.tts.TextToSpeech
  import android.util.Log
  import android.widget.Toast
  import androidx.appcompat.app.AppCompatActivity
  import java.util.*
  
  class MainActivity : AppCompatActivity(), TextToSpeech.OnInitListener {
  
      private var mTTS: TextToSpeech? = null
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          mTTS = TextToSpeech(this,this)
      }
  
      override fun onInit(status: Int) {
          if (status == TextToSpeech.SUCCESS) {
              val result = mTTS!!.setLanguage(Locale.ENGLISH)
              if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                  Log.e(&quot;TTS&quot;,&quot;The Language specified is not supported!&quot;)
              } else {
                  speak(&quot;Nearby places&quot;)
              }
          } else {
              Log.e(&quot;TTS&quot;, &quot;Initilization Failed!&quot;)
          }
      }
  
      private fun speak(mText: String) {
          mTTS!!.speak(mText, TextToSpeech.QUEUE_FLUSH, null, &quot;&quot;)
      }
  
      override fun onDestroy() {
          if (mTTS != null) {
              mTTS!!.stop()
              mTTS!!.shutdown()
          }
          super.onDestroy()
      }
  }
  </code></pre>
  <p>and AndroidManifest.xml is</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.nearbyplaces&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/AppTheme&quot;&gt;
          &lt;activity android:name=&quot;.MainActivity&quot; &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p>With the default blank layout the app works, but displays the default Hello World view (with Title Bar) on top of what was there previously. If I remove the line         <code>setContentView(R.layout.activity_main)</code> and safe delete the activity_main.xml, a blank view with Title Bar is still displayed.</p>
  <p>Following advice on a <a href="https://stackoverflow.com/questions/66304615/android-app-without-ui-how-to-stop-momentary-flash-each-time-the-app-is-run?noredirect=1#comment117389626_66304615">separate thread</a> I tried inserting <code>android:theme=&quot;@android:style/Theme.Translucent.NoTitleBar&quot;</code> in the Manifest. This worked OK with an app that did nothing but display a Toast, but in the app with TextToSpeech code I get the error &quot;You need to use a Theme.AppCompat theme (or descendant) with this activity.&quot;.
  LogCat reports:</p>
  <pre><code>2021-02-28 16:37:40.378 17048-17048/? I/le.nearbyplace: Late-enabling -Xcheck:jni
  2021-02-28 16:37:40.411 17048-17048/? E/le.nearbyplace: Unknown bits set in runtime_flags: 0x8000
  2021-02-28 16:37:41.240 17048-17048/com.example.nearbyplaces I/TextToSpeech: Sucessfully bound to com.google.android.tts
  2021-02-28 16:37:41.304 17048-17048/com.example.nearbyplaces D/AndroidRuntime: Shutting down VM
  2021-02-28 16:37:41.306 17048-17048/com.example.nearbyplaces E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.nearbyplaces, PID: 17048
      java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
          at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:843)
          at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
          at androidx.appcompat.app.AppCompatDelegateImpl.onPostCreate(AppCompatDelegateImpl.java:527)
          at androidx.appcompat.app.AppCompatActivity.onPostCreate(AppCompatActivity.java:127)
          at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1402)
          at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3528)
          at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
          at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
          at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2183)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:241)
          at android.app.ActivityThread.main(ActivityThread.java:7604)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
  2021-02-28 16:37:41.358 17048-17048/com.example.nearbyplaces I/Process: Sending signal. PID: 17048 SIG: 9
  </code></pre>
  <p>Is there a &quot;Theme.AppCompat theme (or descendant)&quot; with NoTitleBar, or any other way of preventing the blank view with Title Bar appearing?</p>