1. 程式人生 > >(轉)慎重使用 android:windowIsTranslucent 主題,其導致啟動app非常慢

(轉)慎重使用 android:windowIsTranslucent 主題,其導致啟動app非常慢

最近做的App,啟動的時候非常慢,點選了桌面的App圖示,等了5~6秒才看見Logo介面,檢查程式碼:
以為問題出現在以下幾點:
1,LogoActivity 處理的 事情太多了.,比如同步伺服器的資料下來匯入本地資料庫中,初始化字型風格;

2,繼承的Application 類中,初始化了
a:SDKInitializer.initialize(this);//百度地圖
b:JPushInterface.setDebugMode(false);JPushInterface.init(this);//極光推送

3,自動登入,重連伺服器方法reLogin();

4,不同手機

在1,2,3點中都設定了開始處理的時間和處理結束的時間,出來的時間都是正常的,0-1秒之間,但是從點選桌面圖示到進入主介面花費了 8 秒左右,當然在LogoActivity 介面設定了延遲3秒,除去了3秒,剩下的5秒哪兒去了呢,花費的時間就是點選桌面圖示到LogoActivity 的onCreate()方法之間的時間.

測試了其他的手機,情況依然如此,煩之又煩 啊.

問題解決:
描述:之前設定android:windowIsTranslucent 主題是為了處理啟動App看見的黑屏,確實是可以處理的

<style name="LogoTheme" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@android:color/transparent</item>//背景是透明的
        <item name="android:windowIsTranslucent"
>true</item>//這裡設定了半透明 <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> </style>

後來去掉android:windowIsTranslucent之後,主題變為

<style name="LogoTheme" parent="android:Theme.NoTitleBar.Fullscreen">
        <item
name="android:windowBackground">@drawable/logo</item>//背景是張logo圖片,這種方式比較好 <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> </style>

該主題是使用於 Android工程資料夾下的AndroidManifest.xml檔案->

<!-- LOGO介面 -->
        <activity
            android:name="com.xxx.activity.LogoActivity"
            android:screenOrientation="portrait"
            android:theme="@style/LogoTheme">//這裡設定主題
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

去掉了android:windowIsTranslucent這個之後在點選桌面圖示.0~1秒就看見了Logo介面.

工作中的點點滴滴,記錄下來,可能也有其他的原因,但是至少去掉android:windowIsTranslucent之後啟動比之前快多了,
如有哪位大神還有更好的解決方法,可以提出,謝謝!