虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > Android编程 > Android冷启动实现app秒开的实现代码

Android冷启动实现app秒开的实现代码
类别:Android编程   作者:码皇   来源:互联网   点击:

本篇文章主要介绍了Android冷启动实现app秒开的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

本文介绍了Android冷启动实现app秒开的实现代码,分享给大家,具体如下:

AndroidManifest里对应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>

如此这样便可以了,当然这只是给用户的一种感觉,并不是真的“秒开”app。

在一个Activity打开时,如果该Activity所属的Application还没有启动,那么系统会为这个Activity创建一个进程,在进程的创建和初始化中,会消耗一些时间,在这个时间里,WindowManager会先加载APP里的主题样式里的窗口背景(windowBackground)作为预览元素,然后才去真正的加载布局。而我上文所做的就是把启动的界面放在style的windowBackground配置里作为预览元素呈现给用户。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关热词搜索: Android冷启动 app冷启动 android app 冷启