经验:
(1)Application的oncreate函数里的耗时操作放在线程里去。
(2)用到的时候再初始化某些第三方SDK,总之最好不要提前调用某些函数,用到的时候再调用。
解决方法:
方法1. 自定义一个theme,修改android:windowBackground为自己的背景图,可以是一个广告页面图片等,这样 就代替了黑屏(白屏)
<style name="AppSplashTheme">
<item name="android:windowBackground">@drawable/app_start_background</item>
</style>
效果:点击后,直接显示自己的广告页面,然后接下来才显示启动页面的界。
方法2:
<style name="AppSplashTheme">
<item name = "android:windowIsTranslucent">true</item>
</style>
效果:点击后,黑白屏是透明的,也就是说用户看到的是桌面,然后接下来才显示启动页面的界面。
方法3:
<style name="AppSplashTheme">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowBackground">@null</item>
</style>
效果:点击后,黑白屏是透明的,也就是说用户看到的是桌面,然后接下来才显示启动页面的界面。
public void onCreate() {
super.onCreate();
File file = new File(Environment.getExternalStorageDirectory(), "run.trace");
Log.i(TAG, "onCreate: " + file.getAbsolutePath());
//把分析结果存在一个文件
Debug.startMethodTracing(file.getAbsolutePath());
//初始化百度地图 SDK
SDKInitializer.initialize(this);
SDKInitializer.setCoordType(CoordType.BD09LL);
Debug.stopMethodTracing();
}
在要测试的代码段的开始和结尾处分别添加上 Debug.startMethodTracing(file.getAbsolutePath())和 Debug.stopMethodTracing();就会在手机存储卡里生成run.trace文件,跟踪了运行状况,将这个文件从手机里导出,然后拖放到Android studio里就会生成性能图。
后续完善此文章给出下示例代码和效果。
本文地址:https://blog.csdn.net/gaoxiaoweiandy/article/details/107191378
如对本文有疑问, 点击进行留言回复!!
Android开发---3种方式教会你炫酷的Android界面缓冲跳转另一界面
出现The style on this component requires your app theme to be Theme.MaterialComponents错误
网友评论