Android开发必会App启动优化(1),含泪狂刷Android基础面试118题

initARouter();

CacheManager.getInstance().initialize(getInstance());

ConnectionManager.getInstance().initialize();

initImageFactory();

initBJY();

initGrowingIO();

initUmeng();

initBugly();

initOkHttp();

initSobot();

setRxJavaErrorHandler();

}

}).start();

将需要在主线程中初始化但是可以不用立使用的控件功能延迟加载:

handler.postDelayed(new Runnable() {

@Override

public void run() {

//延迟初始化组件

}

}, 3000);

注意: 并不是每一个组件的初始化以及操作都可以异步或延迟;是否可以取决组件的调用关系以及自己项目具体业务的需要。保证一个准则:可以异步的都异步,不可以异步的尽量延迟。让应用先启动,再操作。

//子线程初始化第三方组件

//建议延迟初始化,可以发现是否影响其它功能,或者是崩溃!

Thread.sleep(5000);

2、闪屏Activity优化:
Activity的UI层级优化:

优化前UI布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@mipmap/icon_splash_bg">

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:src="@mipmap/icon_splash_word"

android:layout_centerVertical=“true”

android:layout_centerHorizontal=“true”

android:paddingBottom=“160dp”

/>

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_centerHorizontal=“true”

android:src="@mipmap/icon_splash"

android:layout_alignParentBottom=“true”

android:layout_marginBottom="@dimen/dp_41"

/>

<com.pxwx.student.modulecore.widget.TouchRelativeLayout

android:id="@+id/rl_adsRl"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:gravity=“center_horizontal|top”

android:orientation=“vertical” >

<ImageView

android:id="@+id/iv_SplashAd"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@null"

android:contentDescription="@null"

android:scaleType=“fitXY”

android:visibility=“gone” />

</com.pxwx.student.modulecore.widget.TouchRelativeLayout>

<TextView

android:id="@+id/tv_adjump"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:background="@drawable/ad_jump_selector"

android:gravity=“center_vertical|center_horizontal”

android:layout_alignParentRight=“true”

android:layout_marginRight="@dimen/dp_18"

android:layout_marginTop="@dimen/dp_30"

android:paddingBottom="@dimen/dp_5"

android:paddingLeft="@dimen/dp_11"

android:paddingRight="@dimen/dp_11"

android:paddingTop="@dimen/dp_5"

android:text=“跳过 3”

android:textColor="@color/white"

android:textSize="@dimen/font_15"

android:visibility=“gone”

/>

简化后:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@drawable/welcome_layler_drawable">

<ViewStub

android:id="@+id/vs"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout="@layout/layout_stub_avd" />

ViewStub 初始化延迟

针对项目中的启屏广告业务,通过ViewStub延后他们的初始化,在需要显示的时候通过ViewStub的inflate显示真正的view,优化如下

<ViewStub

android:id="@+id/vs"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout="@layout/layout_stub_avd" />

开屏广告业务布局抽取

layout_stub_avd.xml

<?xml version="1.0" encoding="utf-8"?>

<com.pxwx.student.modulecore.widget.TouchRelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:id="@+id/rl_adsRl"

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<ImageView

android:id="@+id/iv_SplashAd"

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background="@null"

android:contentDescription="@null"

android:scaleType=“fitXY” />

<TextView

android:id="@+id/tv_adjump"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:layout_marginTop="@dimen/dp_30"

android:layout_marginRight="@dimen/dp_18"

android:background="@drawable/ad_jump_selector"

android:gravity=“center”

android:paddingLeft="@dimen/dp_11"

android:paddingTop="@dimen/dp_5"

android:paddingRight="@dimen/dp_11"

android:paddingBottom="@dimen/dp_5"

android:text=“跳过 3”

android:textColor="@color/white"

android:textSize="@dimen/font_15" />

</com.pxwx.student.modulecore.widget.TouchRelativeLayout>

然后在代码中需要显示webview时进行inflate:

/**

  • 懒加载广告视图

*/

private void showAvd() {

viewStub = findViewById(R.id.vs);

if (viewStub != null) {

viewStub.inflate();

mAdRl = findViewById(R.id.rl_adsRl);

mAdImage = findViewById(R.id.iv_SplashAd);

mAdJump = findViewById(R.id.tv_adjump);

}

}

优化点:

  1. 废弃之前的启屏页UI布局,直接使用先前自定义好的welcome_layler_drawable作为启屏页背景

  2. 将开屏广告Ui抽取分离

  3. 懒加载广告视图

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

七大模块学习资料:如NDK模块开发、Android框架体系架构…

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
第三,到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示

,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

[外链图片转存中…(img-r12p7lU8-1643525282220)]

七大模块学习资料:如NDK模块开发、Android框架体系架构…

[外链图片转存中…(img-PyAsSieK-1643525282221)]

只有系统,有方向的学习,才能在段时间内迅速提高自己的技术。

这份体系学习笔记,适应人群:
**第一,**学习知识比较碎片化,没有合理的学习路线与进阶方向。
**第二,**开发几年,不知道如何进阶更进一步,比较迷茫。
第三,到了合适的年纪,后续不知道该如何发展,转型管理,还是加强技术研究。如果你有需要,我这里恰好有为什么,不来领取!说不定能改变你现在的状态呢!
由于文章内容比较多,篇幅不允许,部分未展示内容以截图方式展示

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值