Splash Screen Will Not Display
I am trying to implement a Splash Screen using this java and xml code. I created a separate java class from my main activity and placed the java code inside. I created an xml layou
Solution 1:
MainActivity is launcher activity in manifest file. So, splash is not showing.
Change the launcher activity MainActivity to Splash and write another for MainActivity.
<applicationandroid:icon="@drawable/buttonone"android:label="@string/app_name"><activityandroid:name=".Splash"android:label="@string/app_name"android:screenOrientation="portrait"android:configChanges="orientation|keyboardHidden" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:name=".MainActivity" /></application>
Solution 2:
Replace the Handler part with this :
Thread splashThread = new Thread() {
publicvoidrun() {
try {
Thread.sleep(SPLASH_DISPLAY_LENGHT);
} catch (Exception e) {
} finally {
Intent i = new Intent(Splash.this,Menu.class);
startActivity(i);
finish();
}
}
};
splashThread.start();
Solution 3:
privatestaticfinalintSTOPSPLASH=0;
privatestaticfinallongSPLASHTIME=3000;
publicvoidonCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
context = getApplicationContext();
if(savedInstanceState == null){
Messagemsg=newMessage();
msg.what = STOPSPLASH;
spHandler.sendMessageDelayed(msg, SPLASHTIME);
}
}
privateHandlerspHandler=newHandler() {
@OverridepublicvoidhandleMessage(Message msg)
{
switch (msg.what)
{
case STOPSPLASH:
gotoHomeScreen();
break;
default:
break;
}
super.handleMessage(msg);
}
};
publicvoidgotoHomeScreen(){
Intenti=newIntent();
i.setClass(Splash.this,Home.class);
startActivity(i);
finish();
spHandler = null;
}
try this.
in your manifest
<activityandroid:name="Splash"android:configChanges="keyboardHidden"android:theme="@android:style/Theme.NoTitleBar"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
Solution 4:
Try out as below :
publicclassSplashextendsActivity
{
privatefinalintSPLASH_DISPLAY_LENGHT=1000;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
newThread(){
publicvoidrun()
{
try
{
sleep(SPLASH_DISPLAY_LENGHT);
IntentmainIntent=newIntent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
};
}.start();
}
EDITED:
<activityandroid:name=".Splash"android:label="@string/app_name"android:screenOrientation="portrait"android:configChanges="orientation|keyboardHidden" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
Solution 5:
Another way to achieve using CountDownTimer
publicclassMyCounterextendsCountDownTimer {
publicMyCounter(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@OverridepublicvoidonFinish() {
startActivity(newIntent(SplashScreen.this,
TabSample.class));
finish();
MCObject.cancel();
}
@OverridepublicvoidonTick(long millisUntilFinished) {
}
}
Within OnCreate
MyCounter MCObject;
MCObject = newMyCounter(3000, 100);
MCObject.start();
Post a Comment for "Splash Screen Will Not Display"