Android performance optimization tips

使用windowBackground实现应用秒开

1
2
3
4
<style name="SplashTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@drawable/bg_splash_activity</item>
<item name="@android:windowAnimationStyle">@style/myact</item>
</style>

使用windowBackground减少过度绘制

1
2
3
4
5
<style name="AppMainTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:windowBackground">@color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="@android:windowAnimationStyle">@style/myact</item>
</style>

使用windowBackground前后对比

手动清除GPU绘图缓存,降低应用PSS内存值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* 清除GPU绘图缓存
*/
private void cleanGraphicsCache() {
Object instance = ReflectUtils.getStaticMethod("android.view.WindowManagerGlobal",
"getInstance", null, null);

try {
Class threadClazz = Class.forName("android.view.WindowManagerGlobal");
Method m1 = threadClazz.getDeclaredMethod("trimMemory", int.class);
m1.invoke(instance, TRIM_MEMORY_COMPLETE);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}

转载请标明出处病已blog https://ivonhoe.github.io/