Reputation: 27
I make a splashscreen, but my splashscreen don't show up. After 4 seconds the second splashscreen will show up. I want show up my splashscreen for 4 seconds. This is my code:
package com.geven.headsoccer.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
startActivity(new Intent("com.geven.headsoccer.LIBGDX_GAME"));
}
}
Upvotes: 0
Views: 47
Reputation: 5951
You have to use a handler.
new Handler().postDelayed(new Runnable() {
// Using handler with postDelayed called runnable run method
@Override
public void run() {
startActivity(new Intent("com.geven.headsoccer.LIBGDX_GAME"));
// close this activity
finish();
}
}, 4*1000); // wait for 5 seconds
Upvotes: 0
Reputation: 16214
If you want to show your SplashScreen for 4 seconds, why don't you use Handler?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreen.this, MainActivity.class));
finish();
}
}, 4000);
}
Upvotes: 1