These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

Foreword

Android does not the year at its peak, is no longer so hot as in previous years ago. If a new industry experienced very popular, then there must be such a curve like a sine curve we learn to rise rapidly, then reach the top, and then decline, finally reaching a stable value. Then this year is already floating between a saturation value, so in this form, we may have a corresponding high for individual developers of some of the requirements. Android used to be as long as you are a meat and potatoes of the four components, as the era has passed, with the experience requirements of human-computer interaction, require the user to experience the App, fluency, etc., it has been quite different. In this environment, it is the same change to our Android development engineers. As far as I understand, middle and senior engineers still very popular, so I think it should be a proper career planning pyramid, core competencies must be solid!

For now, Android and mobile Internet, we need to master the technology, I made a list of these have a good grasp of 2020. I do not think the problem (# ^ o ^ #):

Generic principles Dian Dian Java Virtual Machine reflection principle principle principle Dian Dian thread pool
annotations principle Dian Dian sequence annotation principles of
Activity knowledge (Activity life cycle of the task stack Dian Dian Activity Activity startup mode of Dian Dian Fragment View source kernel-related Dian )-Service principle like
the code optimization framework (data structure design mode Dian Dian sorting algorithm)
the APP performance optimization (Dian adapted to optimize the user experience Dian tuning codes)
hotfix Hook technology Dian Dian Dian thermal upgrading IOC architecture
NDK (c programming Dian C ++ JNI Dian Dian LINUX)
how to improve development efficiency?
MVC MVP Dian Dian MVVM
micro letter applet
Hybrid
Flutter

1. Android architecture design patterns

  • MVC design patterns: MVC full name is the Model View Controller, is a model (model) - view (view) - abbreviation controller (controller) is.
  • MVP architecture design patterns: MVC full name is Model View Persenter, MVP came from the MVC evolution, it is now mainstream development model.
  • MVVM Architecture Design Patterns: MVVM full name is the Model-View-ViewModel, it is essentially an improved version of MVC.

Various models 主要目的are isolated view (View) and a model (Model), is about to display interface UI and business logic separated.

1.1 architecture design patterns -MVC

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

(1) Definition:

In the android development process, the more popular development framework has been using the MVC framework mode.

  • M (Model) layer: mock treated 业务逻辑. Such as: database operations, network operations, I / O operations, like complicated operations and time-consuming task.
  • V (View) Layers: Processing 数据显示. In Android development, which generally corresponds to the xml layout file.
  • C (Controller) Layers: Processing 用户交互. In Android development, which generally corresponds to the Activity / Feagment . android activity, mainly through user interaction and business logic processing, accept user input and calls the Model and View to fulfill the needs of users.

(2) features

  • Low coupling
  • Reusable and easy to expand
  • Module clear division of responsibilities

(3) Examples

android本身的设计结构符合 MVC 模式。

(4) MVC advantages and disadvantages

  • The advantages of MVC: MVC pattern to control the situation through the Controller, while separated from changes in the Model View display and
  • MVC also have limitations:

View layer corresponds xml layout files can do is very limited, so it is necessary to move the majority of View related operations activity Controller layer. Resulting in activity equivalent to act as two characters (View layer and Controller layer), not only to deal with business logic, but also to operate UI. Once a page of business many complex words, activity code will become bloated and complex.

1.2 architecture design patterns -MVP

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

MVP is from the classic MVC model evolved, their basic ideas have in common places: Controller / Presenter responsible for logic processing, Model provides data, View is responsible for displaying. In Android development, the MVP specific implementation process is that when a request is received View, Presenter, Model layer begins acquiring data, the data is processed. Processed data via the interface and then to the callback Activity View layer or Fragment. Such MVP enables Activity or Fragment become real View, only UI-related things without processing other business processes.

(1) the definition of

  • M (Model) layer: mock treated 业务逻辑. Such as: database operations, network operations, I / O operations, like complicated operations and time-consuming task.
  • V (View) layer: responsible View的绘制以及与用户交互. In Android development, which generally corresponds to the xml file layout and the Activity / Fragment .
  • P (Presenter) layer: complete charge of data between the layer and the Model View layer 交互and 业务逻辑.

(2) Examples

The difference between (3) MVC and MVP of

MVP is not directly used in the Model View, communication between them is performed by Presenter all interactions occur inside the Presenter, and reads the data directly from the MVC Model View Controller through without

  • MVC和MVP的最大区别:MVC的Model层和View层能够直接交互;MVP的Model层和View层不能直接交互,需通过Presenter层来进行交互。
  • Activity职责不同:Activity在MVC中属于Controller层,在MVP中属于View层,这是MVC和MVP很主要的一个区别。可以说Android从MVC转向MVP开发也主要是优化Activity的代码,避免Activity的代码臃肿庞大
  • View层不同:MVC的View层指的是XML布局文件(或用Java自定义的View);MVP的View层是Activity(或Fragment)
  • 控制层不同:MVC的控制层是Activity(或Fragment);MVP的控制层是Presenter,里面没有很多的实际东西,主要负责Model层和View层的交互。

(4) MVP优缺点

  • MVP的优点如下:

模型与视图完全分离,我们可以修改视图而不影响模型;项目代码结构清晰,一看就知道什么类干什么事情;我们可以将一个Presenter用于多个视图,而不需要改变Presenter的逻辑,这个特性非常的有用,因为视图的变化总是比模型的变化更频繁 ;协同工作(例如在设计师没出图之前可以先写一些业务逻辑代码)

  • MVP也有不足之处:

接口过多,一定程度影响了编码效率。一定程度上导致Presenter的代码量过大。
为了降低Presenter中业务繁多的问题,Google又推出了MVVM,试图通过数据驱动来减少Presenter的代码量。

1.3 架构设计模式-MVVM

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

(1) 定义

  • M(Model)层:仍然是实体模型(但是不同于之前定义的Model层),主要负责数据获取、存储和变化,提供数据接口供 ViewModel 层调用。
  • V(View)层:对应Activity/Feagmentxml布局文件 ,负责View的绘制以及与用户交互
    说明:View层仅能操作UI(数据绑定来实现 UI 更新);不能做任何和业务逻辑有关的数据操作
  • VM(ViewModel)层:负责完成Model层和View层间的数据交互业务逻辑
    说明:ViewModel层仅能做和业务逻辑有关的数据操作;不能做UI相关的操作

2. android插件化

插件化来由:随着业务的增多,业务逻辑代码越来越多,apk包也逐渐增大,不利于维护和升级。通过插件化开发可将功能模块解耦,不同的维护团队仅维护某模块的业务,同时当app升级时可仅对某功能模块进行升级而不需整体升级。

2.1 插件化要解决的问题—如何动态加载apk

(1) android类加载器及区别

类加载器作用:java字节码通过类加载器加载到java虚拟器。

  • PathClassLoader:仅能加载文件目录下的apk。
  • DexClassLoader:可以加载apk文件中的字节码(从dex实体jar文件中加载java字节码)。主要用于动态加载和代码热更新等。

(2)反射: java中的反射使我们在运行时获得这个类的属性、方法和class内部的信息机制,最重要的是我们可以在运行时实例化这个对象调用方法,这也是java反射的最大优点。
(3) 实现动态加载apk

什么是动态加载apk:android中有一个速度程序会主动到指定的sd卡中去加载apk,并通过代理activity去执行。

实现:需要一个代理activity去执行apk中的activity,主要通过反射去获得它的属性和方法,从而进行apk的调用。
实现原理:类加载器(加载类)+反射(获取属性和方法)+动态代理(执行)

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

如:

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

2.2 插件化要解决的问题—如何加载资源

通过android中ServiceManager类的隐藏方法来加载资源。

2.3 插件化要解决的问题—如何加载代码

使用java中的类加载机制,但是android和java也有一点不一样,android比java多了组件和生命周期,所以并不是类加载进来就能使用(不能管理生命周期)。

3. Android热更新(在线热修复技术)

(1) 热更新流程

  • 检测到线上严重的crash(参考:app检测crash并发送日志到服务器的实现)
  • 线上版本拉出bugfix分支并在分支上修复问题
  • jenkins构建及生成补丁
  • app在合适时机通过推送或主动拉取补丁文件
  • 将bugfix代码合并到master上

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

(2) 热更新主流框架

  • Dexposed
  • AndFix
  • NuWa

(3) 热更新原理

  • Android类加载机制(类加载器)

PathClassLoader类:用来加载系统类
DexClassLoader:用来加载dex文件、jar文件包和apk包等

  • 热修复机制(原理)

原理:在ClassLoader中创建一个dexElements数组,根据线上的crash定位找到对应的类文件,然后把这个类文件修复完成后打包成一个dex文件并放到dexElements数组的最前方。那么当ClassLoader遍历dexElements数组(加载数组中的dex文件)时,因为ClassLoader会优先加载最前方的dex文件,所以不会加载线上有crash的dex文件,只会加载修复完的dex文件,从而完成热修复过程。

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

4. Android进程保活

(1) 进程保活概念

进程保活:让进程在内存中永远存在且无法杀死,就算被杀死也能保活。
进程被杀死的原因:人为地调用kill;被第三方安全软件杀死。

进程保活并非是一种流氓手段,在很多场景下我们需要一个常驻进程来为用户提供服务,如:

  • 接收屏幕开关的系统广播:因为广播接收者不支持静态注册,必须在进程中动态注册广播接收者来接收,如果没有常驻进程,那么锁屏应用无法为用户正常提供服务。
  • 定位服务:需要在后台维护一个长连接,以便及时地将信息(推送的信息/定位信息等)传达给用户。

缺点:进程保活在内存,不管如何优化,或多或少都会增加性能的开销。所以需在进程保活内存消耗之间寻找平衡点来为用户进程保活。

(2) android进程优先级和回收策略

  • android进程优先级:前台进程 > 可见进程 > 服务进程 > 后台进程 > 空进程
  • android进程的回收策略:主要依靠LMK ( Low Memory Killer )机制来完成。LMK机制通过 oom_adj 这个阀值来判断进程的优先级,oom_adj 的值越高,优先级越低,越容易被杀死。
    拓展:LMK ( Low Memory Killer ) 机制基于Linux的OOM(Out Of Memery)机制,通过一些比较复杂的评分机制,对进程进行打分,将分数高的进程判定为bad进程,杀死并释放内存。LMS机制和OOM机制的不同之处在于:OOM只有当系统内存不足时才会启动检查,而LMS机制是定时进行检查。

(3) android进程保活方案

  • 利用系统广播拉活

在发生系统事件时,系统会发出相对响应的广播(常用的广播事件如:开机、网络状态变化、文件或sd卡的卸载等),我们可以在mainfest.xml文件中静态注册广播监听器
缺点(无法拉活的情形):广播接收者被管理软件或系统软件通过自启动管理等功能禁用的场景下是无法接受广播的,从而无法自启动进行系统拉活;系统广播事件是不可控制的,只有在发生事件时才能进行拉活,无法保证进程被杀死后立即被拉活。

  • 利用系统Service机制拉活

将Service中的onStartCommand()回调方法的返回值设为START_STICKY,就可以利用系统机制在Service挂掉后自动拉活。
拓展:onStartCommand()的返回值表明当Service由于系统内存不足而被系统杀掉之后,在未来的某个时间段内当系统内存足够的情况下,系统会尝试创建这个Service,一旦创建成功就又会回调onStartCommand()方法。
缺点(无法拉活的情形):Service第一次被异常杀死后会在5s内重启,第二次会在10s内重启,第三次会在20s内重启,若Service在短时间内被杀死的次数超过3次以上系统就会不惊醒拉活;进程被取得root权限的管理工具或系统工具通过强制stop时,通过Service机制无法重启进程。

  • 利用Native进程拉活

思想:利用Linux中的fork机制创建一个Native进程,在Native进程可以监控主进程的存活,当主进程挂掉之后,Native进程可以立即对主进程进行拉活。
在Native进程中如何监听主进程被杀死:可在Native进程中通过死循环或定时器,轮询地判断主进程被杀死,但是此方案会耗时耗资源;在主线程中创建一个监控文件,并且在主进程中持有文件锁,在拉活进程启动后申请文件锁将会被阻塞,一旦成功获取到锁说明主进程挂掉了。
如何在Native进程中拉活主进程:主要通过一个am命令即可拉活。
说明:android5.0后系统对Native进程加强了管理,利用Native进程拉活的方式已失效。

  • 利用JobScheduler机制拉活

说明:android在5.0后提供了JobScheduler接口,这个接口能够监听主进程的存活,然后拉活进程。

  • 利用账号同步机制拉活(已失效)

说明:android系统的账号同步机制会定期同步账号信息,这个方案主要是利用账号同步机制进行进程拉活。不过最新的android版本对账号同步机制做了改动,该方法可能不再生效。

学习宝典

对我们开发者来说,一定要打好基础,随时准备战斗。不论寒冬是否到来,都要把自己的技术做精做深。虽然目前移动端的招聘量确实变少了,但中高端的职位还是很多的,这说明行业只是变得成熟规范起来了。竞争越激烈,产品质量与留存就变得更加重要,我们进入了技术赋能业务的时代。

不论遇到什么困难,都不应该成为我们放弃的理由!

Many people new to this industry in the face of time or bottleneck, there will always encounter some problems, such as learning a period of time feel no sense of direction, I do not know from where to start to learn, and I am for Android programmer, I am here for everyone to put together a study book ! Including but not limited to high-level UI, performance optimization, mobile architect, NDK, hybrid development (ReactNative + Weex) micro letter applets, Flutter Android and other advanced practice all aspects of technology; hoping to help you, saving you search on the Internet time information to learn, you can also close friends to share a dynamic learning together!

[Android detailed knowledge thinking brain map (skill tree)]

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

Study notes [Android]

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

For the interview experience, we work experience is not the same questions asked will be different, the interview light back several manufacturers face questions on the thought is quite difficult. But if you already have a favorite approaching the strength of the company's development, you may wish to look at, I Cheats interview experience and authority sites in all kinds of finishing an interview Android according to their own development .

I believe it will bring you a lot of harvest:

These popular Android developers learn cutting-edge knowledge, in 2020 you will have no worries!

[HD brain diagram above], and [supporting] PDF technology architecture can add me wx: X1524478394 free access

When programmers easily, when a good programmer is a need to learn from junior programmer to senior programmer, architect from primary to senior architect, or to management, technical director from technical manager to each stage We need to have different capabilities. Early to determine their career direction, in order to throw off their peers at work and in capacity building.

Guess you like

Origin blog.51cto.com/14332859/2456735