Android闪屏Activity实现秒开

枕上从妨一夜睡,灯前读尽十年诗。这篇文章主要讲述Android闪屏Activity实现秒开相关的知识,希望能为你提供帮助。

1 < !--SplashActivity Theme--> 2 < style name="SplashTheme" parent="AppTheme"> 3< !-- 欢迎页背景--> 4< item name="android:windowBackground"> @drawable/bg_splash< /item> 5< item name="android:windowFullscreen"> true< /item> 6< !-- < item name="android:windowIsTranslucent"> true< /item> --> < !-- 透明背景不要了 --> 7 < /style>

1 < ?xml version="1.0" encoding="utf-8"?> 2 < layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 3< !-- 背景颜色 --> 4< item android:drawable="@color/color_ToolbarLeftItem" /> 5 6< item> 7< !-- 图片 --> 8< bitmap 9android:antialias="true" 10android:gravity="center" 11android:src="https://www.songbingjia.com/android/@drawable/ic_splash" /> 12< /item> 13 < /layer-list>


SplashActivity 不要设置setContentView(R.layout.activity_main);

数据加载放在继承的Application里面,新开线程,在SplashActivity 里面调用即可,如下:
1 ackage com.johnson.kuyqi.mvp.view.activities; 2 3 import android.content.Intent; 4 import android.os.Bundle; 5 import android.os.Handler; 6 import android.support.annotation.Nullable; 7 import android.util.Log; 8 9 import com.johnson.kuyqi.app.base.BaseActivity; 10 import com.johnson.kuyqi.app.kuyqiapp.KuyqiApp; 11 12 /** 13* Created by HelloWord on 2016/12/12. 14*/ 15 16 public class SplashActivity extends BaseActivity { 17 18private static final int SPLASH_SHOW_TIME = 2000; // SplashActivity最小显示时间 19private long mStartTime; // 开始时间 20 21 22@Override 23protected void onCreate(@Nullable Bundle savedInstanceState) { 24super.onCreate(savedInstanceState); 25mStartTime = System.currentTimeMillis(); //记录开始时间, 26Log.i("tag", "mStartTime=" + mStartTime); 27KuyqiApp.getInstance().initData(mHandler); //开始加载数据 28} 29 30@Override 31protected void initFoundView() { 32 33} 34 35@Override 36protected void initView() { 37 38} 39 40@Override 41protected void initEvent() { 42 43} 44 45private Handler mHandler = new Handler() { 46public void handleMessage(android.os.Message msg) { 47switch (msg.what) { 48case KuyqiApp.INIT_DATA_SCUESS:// 如果城市列表加载完毕,就发送此消息 49long loadingTime = System.currentTimeMillis() - mStartTime; // 计算一下总共花费的时间 50if (loadingTime < SPLASH_SHOW_TIME) {// 如果比最小显示时间还短,就延时进入MainActivity,否则直接进入 51mHandler.postDelayed(goToMainActivity, SPLASH_SHOW_TIME - loadingTime); 52} else { 53mHandler.post(goToMainActivity); 54} 55break; 56default: 57break; 58} 59} 60}; 61 62/** 63* 进入下一个Activity 64*/ 65Runnable goToMainActivity = new Runnable() { 66 67@Override 68public void run() { 69SplashActivity.this.startActivity(new Intent(SplashActivity.this, MainActivity.class)); 70finish(); 71} 72}; 73 74 75 }

1 public static void initData(final Handler mHandler) { 2 3new Thread() { 4@Override 5public void run() { 6super.run(); 7mHandler.sendEmptyMessage(INIT_DATA_SCUESS); 8 9} 10}.start(); 11 }

【Android闪屏Activity实现秒开】 

    推荐阅读