My application is unusual: when it starts up, it simply displays a Toast message. That is, I have to click on the launch icon, see Toast and that's it. But after launching, I am less than a second, I see the main application window, which should not be shown at all - only Toast! It is displayed and immediately closed. I use
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast.makeText(this, "This is my Toast message!",
Toast.LENGTH_LONG).show();
finish();
}
What do I need to change?
This is definitely a very strange app.
Although you can launch a Toast
from anywhere you have access to a Context
, you definitely need to use an Activity
due to the need for supplying a Launcher Icon on the homescreen.
However, by default, even if a layout isn't created or 'set', the Activity's window will still show. This is the typical behavior because the behavior has it's own elements and a Layout is simply added inside of this default Activity window.
But this doesn't mean you can't do what you want.
You simply have to make that Activity window not be shown. This is most commonly done through styles.
To do this, you can use this theme:
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Simply add that theme to your Activity inside your 'Manifest.xml'
There are other translucent themes you can try if you don't want to use the FullScreen No Title Bar version.