If you are in the small factory, you have to get to know these

Today to share some of the middle-class interview topics, more suitable for some small plant developers, follow me with a look.

Similarly, regarding the following PDF in all knowledge, is supported by the vast majority of video. Code source. Information and notes for my finishing core PDF notes of interest
https://github.com/xiangjiana/androids

(More complete project download. To be continued. Source. Graphic knowledge subsequent upload github.)

If you are in the small factory, you have to get to know these

Primary interview topics (small plants)

1. What are the reasons leading to memory leaks?

The root cause of memory leaks: Object Object long life cycle of holding short life cycle. Short-period objects can not be released in time.

The difference between static inner classes non-static inner classes (Handler caused by a memory leak.)

Static collections cause a memory leak

Singleton induced memory leaks.

Solve: Context is ApplicationContextdue to ApplicationContextthe life cycle and the app is the same, does not cause a memory leak

Register / unregister the use of unpaired memory leaks caused.

Collection of objects did not clean up the memory leak. Some objects will usually be loaded to the collection, when not in use be sure to remember to clean up a collection, so that the relevant object is no longer referenced.

Reduced memory consumption objects

  • ArrayMap/SparseArrayinsteadhashmap

  • Avoid using inside androidEnum

  • Reduce bitmap memory footprint

    • inSampleSize: Scaling, before the picture into memory, we need to calculate an appropriate scaling, to avoid unnecessary loading the big image.

    • decode format: format decoding, select ARGB_8888 / RBG_565 / ARGB_4444 / ALPHA_8, there is a big difference.
  • Reducing the size of the resource picture, the picture may be considered too large segmented loading
    2, understanding Activity, View, Window relationship among

这个问题真的很不好回答。所以这里先来个算是比较恰当的比喻来形容下它们的关系吧。Activity像一个工匠(控制单元),Window像窗户(承载模型),View像窗花(显示视图)LayoutInflater像剪刀,Xml配置像窗花图纸。

  • Activity构造的时候会初始化一个Window,准确的说是PhoneWindow

  • 这个PhoneWindow有一个“ViewRoot”,这个“ViewRoot”是一个View或者说ViewGroup,是最初始的根视图。

  • ViewRoot通过addView方法来一个个的添加View。比如TextView,Button等

  • 这些View的事件监听,是由WindowManagerService来接受消息,并且回调Activity函数。比如onClickListeneronKeyDown等。
3、Handler的原理

所以就有了handler,它的作用就是实现线程之间的通信。

handler整个流程中,主要有四个对象,handlerMessage,MessageQueue,Looper。当应用创建的时候,就会在主线程中创建handler对象,

我们通过要传送的消息保存到Message中,handler通过调用sendMessage方法将Message发送到MessageQueue中,Looper对象就会不断的调用loop()方法

不断的从MessageQueue中取出Message交给handler进行处理。从而实现线程之间的通信。

4、View,ViewGroup事件分发
  1. Touch事件分发中只有两个主角:ViewGroupViewViewGroup包含onInterceptTouchEventdispatchTouchEventonTouchEvent三个相关事件。View包含dispatchTouchEventonTouchEvent两个相关事件。其中ViewGroup又继承于View。

2.ViewGroup和View组成了一个树状结构,根节点为Activity内部包含的一个ViwGroup

3.触摸事件由Action_Down、Action_Move、Aciton_UP组成,其中一次完整的触摸事件中,Down和Up都只有一个,Move有若干个,可以为0个。

4.当Acitivty接收到Touch事件时,将遍历子View进行Down事件的分发。ViewGroup的遍历可以看成是递归的。分发的目的是为了找到真正要处理本次完整触摸事件的View,这个View会在onTouchuEvent结果返回true。

5.当某个子View返回true时,会中止Down事件的分发,同时在ViewGroup中记录该子View。接下去的Move和Up事件将由该子View直接进行处理。

由于子View是保存在ViewGroup中的,多层ViewGroup的节点结构时,上级ViewGroup保存的会是真实处理事件的View所在的ViewGroup对象:如ViewGroup0-ViewGroup1-TextView的结构中,TextView返回了true,它将被保存在ViewGroup1中,而ViewGroup1也会返回true,被保存在ViewGroup0中。当Move和UP事件来时,会先从ViewGroup0传递至ViewGroup1,再由ViewGroup1传递至TextView

6.当ViewGroup中所有子View都不捕获Down事件时,将触发ViewGroup自身的onTouch事件。触发的方式是调用super.dispatchTouchEvent函数,即父类View的dispatchTouchEvent方法。在所有子View都不处理的情况下,触发AcitivityonTouchEvent方法。

7.onInterceptTouchEvent有两个作用:1.拦截Down事件的分发。2.中止Up和Move事件向目标View传递,使得目标View所在的ViewGroup捕获Up和Move事件。

5、onNewIntent()什么时候调用?(singleTask)
6、mvc 和 mvp mvvm

If you are in the small factory, you have to get to know these
MCP.MVVM项目实战代码.笔记

1.mvc:数据、View、Activity,View将操作反馈给Activity,Activitiy去获取数据,数据通过观察者模式刷新给View。循环依赖Activity,很难单元测试View和Model耦合严重

2.mvp:数据、View、Presenter,View将操作给Presenter,Presenter去获取数据,数据获取好了返回给Presenter,Presenter去刷新View。PV,PM双向依赖

3.mvvm:数据、View、ViewModel,View将操作给ViewModel,ViewModel去获取数据,数据和界面绑定了,数据更新界面更新。

  • viewModel的业务逻辑可以单独拿来测试

  • 一个view 对应一个 viewModel 业务逻辑可以分离,不会出现全能类

  • 数据和界面绑定了,不用写垃圾代码,但是复用起来不舒服
7、自定义控件

View的绘制流程:OnMeasure()——>OnLayout()——>OnDraw()

Step : OnMeasure (): size measurement view. View from the top parent to child View recursively measure method, measure methods and callback OnMeasure.
Step two : OnLayout (): OK View location for page layout. View.layout method call from the top to the parent child View View recursive process, i.e., the parent View size and layout according to the layout parameters measure child View Previous obtained, the child View in the right position. 
The third step : OnDraw (): painting view. ViewRoot create a Canvas object and then call OnDraw ().
Six steps:
①, draw the background view;
②, save the canvas layer (Layer);
③, drawing View the contents of;
④, drawing View child view, if not do not;
⑤, reducing layers (Layer); ⑥, draw the scroll bar.

8 difference, Serializable and Parcelable of

P less memory consumption
network transmission using the program P with the S
S facilitate persistence data
S using the reflection easily trigger a garbage collection slower

Guess you like

Origin blog.51cto.com/14541311/2447181