Android冷啟動實現(xiàn)app秒開的實現(xiàn)代碼
本文介紹了Android冷啟動實現(xiàn)app秒開的實現(xiàn)代碼,分享給大家,具體如下:
AndroidManifest里對應(yīng)activity添加屬性android:theme="@style/AppSplash"
<activity
android:name="com.senyint.edu.college.stu.view.activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/AppSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
@style/AppSplash:
<style name="AppSplash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">@drawable/splash</item>
</style>
@drawable/splash:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap
android:src="@mipmap/splash"/>
</item>
</layer-list>
如此這樣便可以了,當(dāng)然這只是給用戶的一種感覺,并不是真的“秒開”app。
在一個Activity打開時,如果該Activity所屬的Application還沒有啟動,那么系統(tǒng)會為這個Activity創(chuàng)建一個進(jìn)程,在進(jìn)程的創(chuàng)建和初始化中,會消耗一些時間,在這個時間里,WindowManager會先加載APP里的主題樣式里的窗口背景(windowBackground)作為預(yù)覽元素,然后才去真正的加載布局。而我上文所做的就是把啟動的界面放在style的windowBackground配置里作為預(yù)覽元素呈現(xiàn)給用戶。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
分享安裝Android Studio3.6的經(jīng)驗教訓(xùn)
這篇文章主要介紹了Android Studio3.6的安裝錯誤問題及解決方法,非常值得大家參考,現(xiàn)把整個過程分享到腳本之家平臺,需要的朋友參考下吧2020-02-02
Kotlin中的Checked Exception機(jī)制淺析
這篇文章主要給大家介紹了關(guān)于Kotlin中Checked Exception機(jī)制的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
Android編程之線性布局LinearLayout實例簡析
這篇文章主要介紹了Android編程之線性布局LinearLayout用法,結(jié)合實例形式簡單分析了Android線性布局的使用技巧,需要的朋友可以參考下2016-01-01

