I have created a splashscreen for my android app. I went down the route with an activity of it’s own displaying itself in a splashthread and then loading the “MainMenu” acitivty.
This works alright, until I want to quit the app.
When I hit the “back button” I see the MainMenu window. When I hit the “back button” a second time .. I don’t see the splashscreen I see the MainMenu once more. An additional “back” will end the app.
Not nice, are there any good hints on how to avoid that behaviour?
Best of all would of course be to end the app directly when hitting “back” form the “MainMenu” but I guess I then need to re-model the splashscreen to be a part of that activity instead?
Splashcode
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread splashThread = new Thread() {
@Override
public void run() {
try {
Log.d("Trying","Tries");
int waited = 0;
while (waited < 5000) {
sleep(100);
waited += 100;
}
} catch (InterruptedException e) {
Log.d("Catching", e.toString());
} finally {
finish();
Intent i = new Intent(UEABB.this,MainMenu.class);
UEABB.this.startActivity(i);
startActivity(i);
}
}
};
splashThread.start();
}
Regards
Try to explicitly set the
android:noHistory="true"on the SplashScreen Activity in your manifest.xml. I followed a similar approach when designing my “What’s New” Activity.Nevertheless you should call
finish()once you switch to another activity.