I have an issue with my SplashScreenActivity
, when I start my application on my phone it shows a white screen for about 0,5 seconds. The MainActitivy
Thread splashscreen = new Thread() {
public void run() {
try {
Thread.sleep(1000);
Intent mainScreen = new Intent("com.rm.jkrm.MAINACTIVITY");
startActivity(mainScreen);
} catch (InterruptedException e) {
} finally {
finish();
}
}
};
splashscreen.start();
this is your problem UI thread to sleep not a very good idea use handler instead and I think it may cause an exception too.
Handler h=new Handler();
h.postDelayed(new Runnable() {
public void run() {
// TODO Auto-generated method stub
startActivity(new Intent(Splash_Activity.this,Main_Activity.class));
finish();
}
}, 2000);
}
Change SplashActivity theme in the AndroidManifest.xml file to this.
android:theme="@android:style/Theme.Translucent.NoTitleBar"
You need to run this two actions in an AsyncTask:
setContentView(R.layout.splashscreen);
randomSplash();
put the setContentView
in the doInBackground-method and in the postExecute method you run randomSplash
.