Splash Screen In Android Application
I am modifying an open source application and want to add a splash screen to it, Can some one help me in it? When the application starts a black screen appears for 2 to 3 seconds a
Solution 1:
Use class SplashScreen as under
publicclassSplashscreenextendsActivity {
privatestaticfinalintSPLASH_DISPLAY_TIME=3000; /* 3 seconds */publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
newHandler().postDelayed(newRunnable() {
publicvoidrun() {
IntentmainIntent=newIntent(Splashscreen.this,
MainActivity.class);
Splashscreen.this.startActivity(mainIntent);
Splashscreen.this.finish();
overridePendingTransition(R.anim.mainfadein,
R.anim.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}
}
**Add mainfadein.xml & splashfadeout.xml in res->anim folder
mainfadein.xml**
<?xml version="1.0" encoding="utf-8"?><alphaxmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/accelerate_interpolator"android:fromAlpha="0.0"android:toAlpha="1.0"android:duration="1000"></alpha>
splashfadeout.xml
<?xml version="1.0" encoding="utf-8"?><alphaxmlns:android="http://schemas.android.com/apk/res/android"android:interpolator="@android:anim/decelerate_interpolator"android:zAdjustment="top"android:fromAlpha="1.0"android:toAlpha="0.0"android:duration="1000" ></alpha>
and add splash.xml just Add an ImageView and set its background as screen & add image of urchoice in layout
And make Splashscreen class as Launcher and make all other class as HOME in manifest file
Solution 2:
Don't forget to consider that the user might want to quit your app before the splash-delay is over. So clear any pending runnables/messages when the user exits your app.
Example can be found here
Solution 3:
Splash activity
publicclassLaunchScreenextendsActivity {
publicstaticfinallongTIME=3000;
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
Protocol.getInstance(this);
ThreadwelcomeThread=newThread() {
@Overridepublicvoidrun() {
try {
sleep(TIME);
} catch (Exception e) {
Log.e(getClass().getName(), e.toString());
} finally {
startActivity(newIntent(LaunchScreen.this,MainScreen.class));
finish();
}
}
};
welcomeThread.start();
}
}
logo.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_gravity="right"
>
<ImageView
android:id="@+id/logo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/logo"android:layout_centerInParent="true"
>
</ImageView>
</RelativeLayout>
in AndroidManifest :
activity android:name=".LaunchScreen">
<intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter>
</activity>
<activityandroid:name=".MainScreen"android:label="@string/app_name" ></activity>
Post a Comment for "Splash Screen In Android Application"