当前位置: 移动技术网 > IT编程>移动开发>Android > Android冷启动实现app秒开的实现代码

Android冷启动实现app秒开的实现代码

2019年07月24日  | 移动技术网IT编程  | 我要评论

徐至琦丑闻连环爆,我还想她伴奏,宜章信息港

本文介绍了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配置里作为预览元素呈现给用户。

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网