Friday 19 July 2013

Android Splash Screen

Leave a Comment
Today we will covered how to make Android Splash Screen.
Splash is the first screen in the Standard Mobile Application which holds itself for 5-10 seconds before moving to the main screen.
Splash screen is useful where we could initialize application level variable or run any background process.Apart from that, we Could have image of company making that application or application name itself.
 
 After Setting up the project, this is required code that will help you make Splash screen.
 
public class Splash extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash);    // mapping of xml (Splash) into java

// setting up a thread
  Thread splashThread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while (waited < 3000) {       // this screen hold itself for 3sec
sleep(100);
waited += 100;
}
} catch (InterruptedException e) {
// do nothing
} finally {
finish();
Intent i = new Intent();
i.setClass(getBaseContext(), RegisterActivity.class);  // RegisterActivity is the                                                                                                  //activity which opens after the splash screen
startActivity(i);
}
}
};
splashThread.start();   // starting of thread
}

}

In xml :---
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash" >
                                                           <!-- this the image/pic which will come in splash screen
                                                                               saved in drawable folder -->

</RelativeLayout>
 
Result:-
 


Technorati Tags:

0 comments:

Post a Comment