Splash Screen :This is very important screen in mobile application development.Many client demands for splash screen in their application.This is first screen of the application from application flow start.So I have decided to write about splash screen. Following exercise explain about development of splash screen in android.
Steps 1.Create splash Activity :
public class SplashScreen extends Activity {
long spalshTime =3000;
boolean isPaused =false;
boolean isSplashActive =true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Draw the splash screen
setContentView(R.layout.splash);
//very simple timer thread
Thread splashTimer = new Thread(){
public void run(){
try{
//wait loop
long ms=0;
while ( isSplashActive && ms <spalshTime) {
sleep(100);
//increase the timer if only we r running
if (!isPaused) {
ms +=100;
}
}
//Advance to the next screen
startActivity(new Intent("com.mainScreen"));
}catch(Exception e){
}finally{
finish();
}
}
};
splashTimer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
isPaused=true;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
isPaused=false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isSplashActive =false;
}
return true;
}
}
Steps 2.Create Manifest file like,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SplashScreen"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SplashScreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MainScreen">
<intent-filter>
<action android:name="com.mainScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
That's it.Enjoy androing...!!!
Steps 1.Create splash Activity :
public class SplashScreen extends Activity {
long spalshTime =3000;
boolean isPaused =false;
boolean isSplashActive =true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Draw the splash screen
setContentView(R.layout.splash);
//very simple timer thread
Thread splashTimer = new Thread(){
public void run(){
try{
//wait loop
long ms=0;
while ( isSplashActive && ms <spalshTime) {
sleep(100);
//increase the timer if only we r running
if (!isPaused) {
ms +=100;
}
}
//Advance to the next screen
startActivity(new Intent("com.mainScreen"));
}catch(Exception e){
}finally{
finish();
}
}
};
splashTimer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
isPaused=true;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
isPaused=false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isSplashActive =false;
}
return true;
}
}
Steps 2.Create Manifest file like,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SplashScreen"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SplashScreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MainScreen">
<intent-filter>
<action android:name="com.mainScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
That's it.Enjoy androing...!!!
No comments:
Post a Comment