In this tutorial I’m going to show you how to easily create an android splash screen in your application.

The whole idea of this sample implementation is to start and display an activity for a certain amount of time and then start new activity. Our activity code is listed below.

SplashActivity.java

package com.itcuties.tutorial.android; import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;import android.view.Window;import android.view.WindowManager; 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);       this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar       setContentView(R.layout.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();      }   }}

As you see the implementation is really simple. We have a private class which is responsible for waiting some amount of time and launching a main activity in a new thread. We construct and start this thread at the end of onCreate method when a view has been set.

Remember that SplashActivity is the starting activity of our application so don’t forget to set android.intent.category.LAUNCHER category in Your AndroidManifest.xml file. Our sample manifest file code looks like this

AndroidManifest.xml

< manifest xmlns:android = "http://schemas.android.com/apk/res/android" package = "com.itcuties.tutorial.android" android:versionCode = "1" android:versionName = "1.0" > < uses-sdk android:minSdkVersion = "7" android:targetSdkVersion = "7" /> < application android:icon = "@drawable/ic_launcher" android:label = "@string/app_name" android:theme = "@style/AppTheme" > < activity android:name = ".SplashActivity" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > < activity android:name = ".MainActivity" android:label = "@string/title_activity_main" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> </ intent-filter > </ activity > </ application > </ manifest >

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. surfaceView 与view
  2. Android 关于GridView 以及图片处理一些
  3. 使用Android studio 查看其它app的布局的
  4. Google 菜市场(Android Market)上不去的解
  5. Android注解原理与常用注解框架
  6. Android 外接键盘的按键处理
  7. [android]android自动化测试十四之dumpsy
  8. android客户端与服务器交互数据(基于SAOP
  9. android studio-GridLayout网格布局设计
  10. Android 消息推送(二)基于 MQTT 协议实现的