APP启动优化

1. 去除启动黑屏

1.1 在style.xml中定义两种主题:

<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
   <item name="android:windowIsTranslucent">true</item>
</style>

<style name="AppTheme.Splash">
   <item name="android:windowIsTranslucent">false</item>
   <item name="android:windowBackground">@drawable/bg_splash</item>
</style>

1.2 在AndroidManifest.xml中设置MainActivity的主题为AppTheme.Splash

<activity
  android:name="xxx.MainActivity"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme.Splash">
  <intent-filter>
      <action android:name="android.intent.action.MAIN"/>
      <category android:name="android.intent.category.LAUNCHER"/>
  </intent-filter>
</activity>

1.3 在MainActivityonCreate调用super的方法之前设置回原先的主题

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
  }

2. 分析启动卡顿

写在后面:

1. 子曰:「学而不思则罔,思而不学则殆」。
2. 站点地图
2. 本作品作者为 Lshare,采用知识共享署名 4.0 国际许可协议进行许可。
原文地址:https://www.cnblogs.com/lshare/p/11333994.html