Android: The Splash Screen Does Not Get Shown, Why?
Solution 1:
I believe your splash screen never gets shown because you never give the UI thread (that you are in) a chance to draw it since you just sleep there doing nothing.
Instead of the Thread.sleep, I would suggest you look into a Timer or something like that to schedule the refresh and changing the content of your view; an alternative would be to start an AsyncTask where you could sleep before changing the view as you are doing now.
Do not sleep or in any other way block the UI thread, that's bad... (causes ANR)
Solution 2:
When you call sleep
like that, you are blocking the UI thread. Instead, put the second call to setContentView
in a Runnable
, create a Handler, and use the Handler's postDelayed
method to run the Runnable. Something like this:
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Runnable endSplash = newRunnable() {
@Overridepublicvoidrun() {
setContentView (R.layout.main);
}
}
newHandler().postDelayed(endSplash, 5000L);
}
Solution 3:
I have tried this code in my application and its working perfectly.May be it will help you.
publicclassSplashScreenextendsActivity {
/**
* The thread to process splash screen events
*/private Thread mSplashThread;
/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.splash);
finalSplashScreensPlashScreen=this;
// The thread to wait for splash screen events
mSplashThread = newThread() {
@Overridepublicvoidrun() {
try {
synchronized (this) {
// Wait given period of time or exit on touch
wait(5000);
}
} catch (InterruptedException ex) {
}
finish();
// Run next activityIntentintent=newIntent();
intent.setClass(sPlashScreen, MainActivity.class);
startActivity(intent);
stop();
}
};
mSplashThread.start();
}
@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
returnfalse;
}
/**
* Processes splash screen touch events
*/@OverridepublicbooleanonTouchEvent(MotionEvent evt) {
if (evt.getAction() == MotionEvent.ACTION_DOWN) {
synchronized (mSplashThread) {
mSplashThread.notifyAll();
}
}
returntrue;
}
}
Solution 4:
This is the snippet for a basic splash screen
publicclassSplashextendsActivity {
//private ProgressDialog pd = null;privatefinalintSPLASH_DISPLAY_LENGTH=3000;
/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
//this.pd = ProgressDialog.show(this, "Initializing..", "Initializing Infraline...", true, false);/* New Handler to start the InfralineTabWidget-Activity
* and close this Splash-Screen after some seconds.*/newHandler().postDelayed(newRunnable(){
@Overridepublicvoidrun() {
/* Create an Intent that will start the InfralineTabWidget-Activity. */IntentmainIntent=newIntent(Splash.this,InfralineTabWidget.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
And in your AndroidManifest.xml put
<activityandroid:name=".Splash"android:theme="@android:style/Theme.NoTitleBar"android:configChanges="orientation|keyboardHidden"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
Hopefully this works for you :)
Post a Comment for "Android: The Splash Screen Does Not Get Shown, Why?"