1

I want to create an activity that simply displays a Toast (or speaks a message) then quits. Following the advice in https://www.quora.com/Is-it-possible-to-create-an-Android-app-that-does-not-have-a-UI I have (using Android Studio) created a blank app, then "safe deleted" the layout xml file and REMoved the setContentView line in MainActivity. This seems to work fine except that, each time the app is run, the previous screen (the layout of whatever app is already running) starts to make way for a new blank white layout, and then after a fraction of a second the previous screen comes back. The effect is a momentary white flash each time the app is run.

How do I stop the white flash appearing?

prepbgg
  • 3,564
  • 10
  • 39
  • 51
  • What theme are you using? – CommonsWare Feb 21 '21 at 16:44
  • https://developer.android.com/guide/topics/ui/look-and-feel/themes says "Android Studio ... applies a material design theme to your app by default", so I guess the answer is "material design." I simply created a New Project with an Empty activity. – prepbgg Feb 21 '21 at 17:48
  • 1
    On your `` element in your manifest, add `android:theme="@android:style/Theme.Translucent.NoTitleBar"` and see if that helps. Note that you might already have an `android:theme` attribute that this would replace. – CommonsWare Feb 21 '21 at 17:59
  • Great. Thanks. That works. I had to work out that the code you supplied needed to be inserted into the activity tag (if that's the right terminology) between . Should I submit an answer setting out the amended Manifest code? – prepbgg Feb 21 '21 at 18:10
  • "I had to work out that the code you supplied needed to be inserted into the activity tag (if that's the right terminology) between " -- that is how XML attributes work. "Should I submit an answer setting out the amended Manifest code?" -- sure! – CommonsWare Feb 21 '21 at 18:12
  • "that is how XML attributes work." OK, but in my ignorance I first tried putting inside the along with and Thanks again for your help and guidance. – prepbgg Feb 21 '21 at 19:10
  • "but in my ignorance I first tried putting inside the " -- ah, I see! Yeah, these manifest entries take some getting used to! – CommonsWare Feb 21 '21 at 19:17
  • After extending the app to implement TextToSpeech code I get a "You need to use a Theme.AppCompat theme (or descendant)" error. Can you explain how I should modify the code to get past this, please? – prepbgg Feb 27 '21 at 16:12
  • Sorry, I do not know of an `AppCompat` option for you. More importantly, the implication of the error is that you are trying to how some UI. I recommend that you ask a separate Stack Overflow question, where your [mcve] shows the complete stack trace, along with your code that is referenced in that stack trace. – CommonsWare Feb 27 '21 at 16:30

1 Answers1

1

The answer (thanks to Commonsware) is to insert android:theme="@android:style/Theme.Translucent.NoTitleBar" in the <activity> element in the manifest. The whole amended activity element reads:

    <activity android:name=".MainActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
prepbgg
  • 3,564
  • 10
  • 39
  • 51