Splash screen for Android


<pre>public class MyClass extends Activity {
	String TAG ="on Splash Screen";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		setContentView(R.layout.splash_screen);
		/** set time to splash out */
		final int welcomeScreenDisplay = 5000;
		/** create a thread to show splash up to splash time */
		Thread welcomeThread = new Thread() { 

			int wait = 0;

			@Override
			public void run() {
				try {
					super.run();
					/**
					 * use while to get the splash time. Use sleep() to increase
					 * the wait variable for every 100L.
					 */
					while (wait &lt; welcomeScreenDisplay) {
						sleep(100);
						wait += 100;
					}

				} catch (Exception e) {
					   Log.e(TAG, "Exception"+e);
				} finally {
					/**
					 * Called after splash times up. Do some action after splash
					 * times up. Here we moved to another main activity class
					 */
					startActivity(new Intent(MyClass.this,
							NewClassName.class));
					finish();
				}
			}
		};
		welcomeThread.start();
    }
}</pre>

 

Comments are closed.