Thursday, February 21, 2013

How to create a splash screen


public class SplashActivity extends Activity {

                 private static String TAG = SplashActivity.class.getName();
                   private static long SLEEP_TIME = 5;    // Sleep for some time
                                   @Override
                   protected void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.activity_splash);
                 
                      // Start timer and launch main activity
                      IntentLauncher launcher = new IntentLauncher();
                      launcher.start();
                   }
                 
                   private class IntentLauncher extends Thread {
                      @Override
                      /**
                       * Sleep for some time and than start new activity.
                       */
                      public void run() {
                         try {
                            // Sleeping
                            Thread.sleep(SLEEP_TIME*1000);
                         } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                         }
                 
                         // Start main activity
                         Intent intent = new Intent(SplashActivity.this,mainactivity.class);
                         SplashActivity.this.startActivity(intent);
                         SplashActivity.this.finish();
                      }
                   }
}


In manifest

<activity
           . . . . . .
             android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

. . . . . . . . . .
           >
        </activity>

No comments:

Post a Comment