Some say it is the primary Android engineers face through? It scared me!

Some say it is the primary Android engineers face through?  It scared me!

This article from author Xiao cold months , the article introduces his interview Android development engineers throughout the process codified knowledge system, I believe it will be helpful to everyone! By the way, the authors say this is the initial Android engineer's face was, I think not, this difficulty has scared me. .

Java foundation

What is the optimistic locking?

Optimistic locking: let's say a pick up data that others will not be modified, so it will not be locked. But when the update will determine what others do not have to update the data during this period. More generally used in reading, writing relatively few cases.

Pessimistic locking: assume the worst-case every time, every time someone else will pick up the data changes, so every time you take the data will be locked, so people want to take this data will be blocked until it got the lock, and more used when writing less reading.

volatile keyword

  1. Ensure visibility, does not guarantee atomicity
  2. Prohibit instruction reordering
  3. Not cached, each time taken from the main memory

hashmap principle, what red-black tree?

  • + Array list, while the list is too long, it will lead to degradation of query efficiency
  • + + Red-black tree list array, when the chain length is greater than 8 into a red-black tree
  • HashMap default initial size of 16, initial size must be a power of 2, the maximum size of 2 to the 30th power. Entry class list node stored in the array Map.Entry implemented in the interface, which implements the general operation of the node. HashMap threshold value defaults to "Capacity * 0.75f", when the number of storage nodes exceeds this value, then the map for the expansion process.
  • Thread-safe container, to solve the problem of concurrent use ConcurrentHashMap (efficient) or Collections.synchronizedMap (). Collections.synchronizedMap () for each method is actually a plus synchronize, and in fact almost HashTable.

Red-black tree

  • Balanced binary search tree
  • Node is red or black
  • The root node is black
  • Each leaf node node are black empty (NULL)
  • Each of the two child nodes red node are black
  • All the paths from any node to each leaf node contains the same black
  • It involves insertion and rotation discoloration

jvm memory allocation

  • Program Counter
  • Java Virtual Machine stack
  • Native method stacks
  • Java heap
  • Methods district
  • Runtime constant pool
  • Direct Memory

String,StringBuffer,StringBuilder 区别

Char array are String, StringBuffer, StringBuilder and eventually the underlying storage operation. But inside the char array String is final, and StringBuffer, StringBuilder is not, that is to say, String is immutable, wants a new string can only regenerate String. The StringBuffer and StringBuilder only need to modify the underlying array of char on the line. Relatively speaking, the cost is much smaller.

Most of the methods are again new String a new String object is returned, frequently regenerate easily generate a lot of garbage. StringBuffer is thread-safe, StringBuilder is not thread-safe, because the method is the addition of synchronized StringBuffer locked up, but StringBuilder is not. Additions and deletions relatively long time with StringBuffer or StringBuilder (note that single-threaded and multi-threaded). The actual situation of demand and take it, since it already knows the principles inside.

Some say it is the primary Android engineers face through?  It scared me!

Andrews basis

Andrews big changes in each version (Android 6.0 Dao 10.0), compatible adapter

Android 5.0

  • Material Design
  • ART Virtual Machine

Android 6.0

  • Application Rights Management
  • Official support for fingerprint
  • Doze power management
  • Runtime rights mechanisms -> dynamic application needs permission

Android 7.0

  • Multi-window mode
  • Language platform supports Java 8
  • FileProvider need to use to access photos
  • Install apk need to be compatible

Android 8.0

  • Notice
  • Picture in Picture
  • Autofill
  • Background restrictions
  • Adaptive desktop icon -> Adapter
  • Implicit broadcast restrictions
  • Open backstage Service restrictions

Android 9.0

  • Use Wi-Fi RTT indoor positioning
  • Liu screen support API
  • Support for multi-camera and camera updates
  • The caller does not hide api
  • Expressly limit the flow of network requests http

Android 10

  • Dark Mode
  • Privacy Enhanced (background can access positioning)
  • Restrict program access Clipboard
  • Application of Black Box
  • Granular rights need to be compatible
  • Background locate individual rights to be compatible
  • Device unique identifier to be compatible
  • Activity open in the background to be compatible
  • Non-limiting SDK interfaces to be compatible

Hot Fix principle

principle

  1. Andrews when loading the class will be to load a class by parents delegation mechanism, let the parent class to load, if no let subclass to load a class.
  2. ClassLoader found by viewing the source code findClass method is implemented by each subclass own, such as BootClassLoader or BaseDexClassLoader. The PathClassLoader is inherited from BaseDexClassLoader, its findClass also implemented in BaseDexClassLoader inside.

  3. BaseDexClassLoader findClass inside of another object DexPathList used to find the corresponding class, which is inside the Android-specific implementation. In DexPathList objects inside a property dexElements, dexElements is used to store loads of good dex arrays look from this class is to look inside the dexElements array.

  4. dexElements which is stored Element object, findClass eventually handed over to achieve Element, Element to Element will inside a property DexFile to achieve. I looked, and ultimately with the native implementation.

  5. DexPathList object Back to the top step 3 from dexElements look inside the array class, looking back from the front of the array, it returns the results found, look no further.
  6. So when we repaired the bug's class, mess dex, and then into the front dexElements by reflection technology, so the system is found in the class by PathClassLoader, will be able to find a good bug fix we placed the class, then after just will not go down looking, achieved the equivalent of a hot fix. This has the bug class will not be used. Should the old saying, proximity and easier.
  7. Point 6 of the reflection process is: acquired PathClassLoader, the object is then reflected acquired DexPathList parent class, and then reflected to the array dexElements DexPathList object. Then patch (DEX) Switch Element object, inserted before dexElements array (first copy out, then combined, and then put back by reflection).

Sentence summary. The class in good repair dexElements the front, so that when the loaded class will be loaded into the priority to achieve the purpose of repair.

MVC,MVP,MVVM

First of all you need to know is how to design technical framework? Certainly for low coupling and improve development efficiency is not it. So do not be to design and design.

MVC

In the View and Android Controller it is to be act as a general Activity, and when the logic is very large, very complex operations, Activity code amount is very large and difficult to maintain.

  • Model: model layer, business logic, data storage +
  • View: The user interface in general is xml + Activity
  • Controller: control layer, is generally Activity

MVP

My personal point of view, now (October 29, 2019 20:02:49) mostly this way, neither the complex also decoupled.

  • Model: model layer, business logic, data storage + + network requests
  • View: layer View, View drawing and other user interaction, typically Activity
  • Presenter: presentation layer, a connecting layer, and M layer V, complete interaction between them

MVVM

To be more separation M, V layer, with MVVM.

  • Model: model layer, business logic, data storage + + network requests
  • View: layer View, View drawing and other user interaction, typically Activity
  • ViewModel: in fact, fit Presenter View, and data model. Two-way binding, View changes would react to the ViewModel, the data will react to changes in the View.

Component-based benefits

  1. Any changes need to compile the entire project and inefficient.
  2. Decoupling will help people develop teamwork
  3. Multiplexing function

app startup process

  1. Launcher startActivity
  2. AMS startup activity
  3. Zygote fork process
  4. Activity main()
  5. ActivityThread process loop cycle
  6. Open Activity, began lifecycle callbacks ...

Activity start the process

  1. Activity startActivityForResult
  2. Instrumentation execStartActivity
  3. AMS startup activity
  4. ApplicationThread scheduleLaunchActivity
  5. ActivityThread.H handleMessage -> performLaunchActivity
  6. Activity attach
  7. Instrumentation callActivityOnCreate

Optimization of the volume of app

You can use lint tools to detect the file useless. While open resource compression, automatically delete unused resources. Use as much drawable, some images do not need resources still image, the frame can be dynamically rendered image at run time. Try to write your own Drawable, UI can not cut plan would not have a small footprint.

Reuse of resources, such as a triangle button, click on the triangle facing up on behalf of the former put away the meaning, click on the triangle down, on behalf of expansion, under normal circumstances, we will use two maps to switch, we can actually go in the form of rotation change. For example, different colored the same image, we can use android: tint and tintMode properties, low version can be used ColorFilter.

PNG and JPEG file compression can reduce the size of PNG files without losing image quality. Use WebP file format, you can use WebP file format, instead of using PNG or JPEG file. AS can be used to convert existing BMP, JPG, PNG, or GIF images into static WebP format. Use of vector graphics .svg; code obfuscation using proGuard code obfuscation tool, which includes a compression, optimization, etc. confusion. This all too familiar. Plug of the functional modules placed on a server, downloaded on demand, can reduce the size of the installation package.

app launch Optimization

Use show out in advance Window, quickly it came up with a show program, rapid feedback to the user experience. Cover-up, a palliative.

Avoid doing intensive heavy initialization (Heavy app initialization) at startup. Some SDK on asynchronous initialization to load (such as Friends of the Union, bugly such non-essential services can be loaded asynchronously), such as maps, push, etc., is not the first time need to be done on the main thread of the delayed start (such as splash screen page ), when the program has been started up, and then initialized. For the network, the picture frame request must be initialized in the main thread. At startup, avoiding I / O operation, deserialization, network operations, the layout nesting consuming operations.

app layout optimization

  • If the parent control has color, but also their own desired color, then you do not have to add background color of a child control
  • If the child control has a background color, and can completely cover the parent control, then the parent controls do not set the background color
  • Minimize unnecessary nesting
  • Can LinearLayout and FrameLayout, do not use RelativeLayout, because RelativeLayout relatively complex, mapping is relatively time consuming.
  • Use include and merge together, increase reuse, reduce levels
  • ViewStub loaded on demand, more lightweight
  • Complex interface options ConstraintLayout, can effectively reduce the level of

app memory optimization

Frequently used with string concatenation or StringBuilder StringBuffer; ArrayMap, SparseArray replace the HashMap; avoid a memory leak.

  • Collections leakage (the collection has been referenced element object is added incoming)
  • Singleton / Static variables caused by a memory leak (long life cycle of holding the short life cycle of reference)
  • Anonymous inner class / non-static inner classes
  • Resources are not closed due to a memory leak
  • Several memory leak detection tools: LeakCanary, TraceView, Systrace, Android Lint and Memory Monitor + mat

What a memory leak

  • Collections leakage (the collection has been referenced element object is added incoming)
  • Singleton / Static variables caused by a memory leak (long life cycle of holding the short life cycle of reference)
  • Anonymous inner class / non-static inner classes
  • Resources are not closed due to a memory leak
  • Networks, files and other streaming forget to turn off
  • Manual registration broadcast, when exiting forget unregisterReceiver ()
  • Service after the execution is completed forget stopSelf ()
  • EventBus framework such as the observer pattern forget to manually deregister

app threading optimizations

Thread pool to avoid the large number of Thread, reuse internal thread pool thread, thus avoiding the thread creation and destruction caused by the performance overhead, and can effectively control the maximum number of concurrent thread pool thread to avoid a large number of system resources due to seize another causing line blocking phenomenon.

classification

  • FixedThreadPool number of fixed thread pool
  • CachedThreadPool only non-core thread, a variable number, there is idle thread time-out mechanism, more suitable for a lot less time-consuming task execution
  • ScheduledThreadPool core thread fixed number of non-core thread is no limit. The main tasks having a timing for performing repetitive tasks in a fixed period.
  • SingleThreadPool only one core thread to ensure that all tasks in order to perform the same thread, unified external tasks to a thread, which makes the problem of synchronization between threads in the need to deal with these tasks.

advantage

  • Reduce overhead in creating and destroying threads as well as the time it takes system resources
  • Do not use the thread pool may cause the system to create a large number of threads resulting in system memory and consumed "over-switching"

important point

  • If the number of threads in the pool does not reach the number of kernel threads, directly start a kernel thread to perform tasks
  • If the number of threads in the pool has reached or exceeded the number of kernel threads, it will be inserted into any task queue waiting to be executed
  • If the 2 tasks can not be inserted into the task queue, because the task queue is full, this time if the maximum number of threads in the thread pool does not meet the provisions, it will start a thread to perform non-core tasks
  • If the number of threads in the thread pool 3 has reached the maximum, it will refuse to perform this task, ThreadPoolExecutor calls rejectedExecution RejectedExecutionHandler's () method tells the caller

How to achieve skinning Android, principle

Reset LayoutInflater of Factory2, in order to intercept the process of creating a View, and then into an own controls, like how on how resurfacing peels.

fresco principle, glide principle, the difference between the two, which is more provincial memory

Temporarily do not understand this, add todo.

Handler principle, Android messaging

Prior wrote an article, Sike everything you need to know Android_Handler mechanism, which describes it in detail, why the way the loop will not block the main thread issues.

The key lies in understanding the mechanism Handler ThreadLocal principles thread private data. Looper use ThreadLocal mechanism will be stored to the internal thread, perfect!

Android System Architecture

Some say it is the primary Android engineers face through?  It scared me!

The application layer, application framework layer, layer runtime system, hardware abstraction layer and the Linux kernel layer.

What are commonly used layout

  • FrameLayout
  • LinearLayout
  • RelativeLayout
  • ConstraintLayout
  • CoordinatorLayout

There are several ways to store data Android

  • SharedPreferences: little things, ultimately xml file, key-value stored in the form.
  • file
  • database
  • ContentProvider
  • The internet

View,SurfaceView

  • Android View is the base class for all controls
  • View update applies to the case of the initiative, and is applicable to the case of passive SurfaceView updates, such as frequently refreshed interface.
  • View the page is refreshed in the main thread, and then open a sub-thread SurfaceView to refresh the page.
  • View does not implement double buffering mechanism when the drawing, SurfaceView the underlying mechanism to achieve a double buffering mechanism.

jni call flow

I also wrote a simple demo before calling JNI Java and C each other with basic operations.

Mutual references between components, how to solve

  • External calls the other components to provide a method: before an idea seen by way of "Realization Interface", the definition of a ComponentBase intermediate layer, and there is provided a method of external Interface calls each component, each component in the initialized Interface to put these when achieved, and other components when needed on ComponentBase taken from inside.
  • Interface Jump: ARouter

Android Digital Signature

Verify user identity, data integrity check.

fragment with where the difference between Activity

  • Activity time when the need for modular
  • Adaptation on different devices, such as mobile phones and platforms
  • Fragment Activity relative terms, is very cumbersome, generally small interface modules with small Fragment appropriate, the Home tab or the like.

View principles draw

主要是分析measure,layout,draw的过程,之前写过一篇比较完整的,如下。死磕Android_View工作原理你需要知道的一切:

https://blog.csdn.net/xfhy_/article/details/90270630

Retrofit和OkHttp原理,拦截器

  • Retrofit的话,源码写的非常非常棒。主要是通过动态代理+获取方法上面的注解等,然后组装请求网络的参数,最后用OkHttp去请求网络。
  • OkHttp的拦截器链设计得非常巧妙,是典型的责任链模式。并最终由最后一个链处理了网络请求,并拿到结果。

点击事件传递机制,事件分为哪几种

事件传递大体过程:Activity--> Window-->DecorView --> View树从上往下,传递过程中谁想拦截就拦截自己处理。MotionEvent是Android中的点击事件。主要事件类型:

  • ACTION_DOWN 手机初次触摸到屏幕事件
  • ACTION_MOVE 手机在屏幕上滑动时触发,会回调多次
  • ACTION_UP 手指离开屏幕时触发

需要关注的几个方法。

  • dispatchTouchEvent(event);
  • onInterceptTouchEvent(event);
  • onTouchEvent(event);

上面3个方法可以用以下伪代码来表示其关系:

public boolean dispatchTouchEvent(MotionEvent ev) {
    boolean consume = false;//事件是否被消费
    if (onInterceptTouchEvent(ev)) {//调用onInterceptTouchEvent判断是否拦截事件
        consume = onTouchEvent(ev);//如果拦截则调用自身的onTouchEvent方法
    } else {
        consume = child.dispatchTouchEvent(ev);//不拦截调用子View的dispatchTouchEvent方法
    }
    return consume;//返回值表示事件是否被消费,true事件终止,false调用父View的onTouchEvent方法
}

anr如何产生,Service触发anr是多长时间(20秒),如何解决anr?如何解决那种莫名其妙的anr?

我觉得anr就是在主线程做了耗时操作,比如io、读写文件、数据库操作等等。anr发生之后一般会有日志,在/data/anr/traces.txt里面。可以参考我的这篇文章拿anr日志,Android 未root查看ANR异常:

https://blog.csdn.net/xfhy_/article/details/80223190

Dialog和Activity是同一个Window?

不是同一个。

  • Activity的attach方法,这里是为Activity实例化了一个PhoneWindow实例
  • Dialog的构造方法里面也是实例化了一个PhoneWindow实例

Window,Activity,Dectorview之间的关系

Activity里面实例化了一个Window,Window里面有一个DecorView(根布局)。看一下这篇文章,Android Window机制探索:

https://blog.csdn.net/qian520ao/article/details/78555397

ConstraintLayout和RelativeLayout在绘制方面有何差别?

todo。

onClick事件和onTouchListener在哪里回调?

如果一个View需要处理事件,它设置了OnTouchListener,那么OnTouchListener的onTouch方法会被回调。如果onTouch返回false,则onTouchEvent会被调用,反之不会。在onTouchEvent方法中,事件为Action.UP的时候会回调OnClickListener的onClick方法,可见OnClickListener的优先级很低。

LinearLayout是如何测量(measure)的?如果有weight又是如何测量的?

先做一次测量,做完之后有空间剩余,有weight的View再测量一下,分一下剩余的空间。

屏幕适配

先前有鸿洋的AndroidAutoLayout,根据宽高进行控件缩放,非常经典,很多项目可能都还在使用,但是已经停止更新了。然后就是有名的今日头条方案,出来还是有点时间了。原理其实就是更改density。

屏幕的宽度=设计稿宽度 * density。

然后有AndroidAutoSize库,将今日头条方案融合进去还完善了很多问题,易用,完美。

其他

Java四种引用

  • 强引用,默认就是,宁愿OOM,也不回收
  • 弱引用,内存不够会被回收
  • 软引用,GC时会被回收
  • 虚引用,它的作用在于跟踪垃圾回收过程,在对象被收集器回收时收到一个系统通知。

项目中遇到的最困难的事情是什么?如何解决的?

每个人遇到的情况不同,这个提前思考一下自己做过的项目最有挑战的地方。

Kotlin优势

  • 完全兼容java
  • 空安全
  • 支持lambda表达式
  • 支持扩展函数
  • 更少的代码量,更快的开发速度

缺点就是有时候代码阅读性可能会降低。

Kotlin 协程是什么?

就是一个线程框架,提供了一套操作线程的api。

二叉树,广度优先遍历,深度优先遍历

推荐小灰的漫画算法。还有其他的一些,随便聊聊:

  • tcp,http,https,socket
  • 敏捷开发
  • 你经常使用哪些设计模式,常见设计模式的运用
  • 3年之后工资怎么想的
  • 你的优势
  • 职业规划(3年后干啥,5年后干啥)
  • 应用,进程,线程之间的区别

最后

有些东西你不仅要懂,而且要能够很好地表达出来,能够让面试官认可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。

对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

文章中每一个部分都包含一系列BAT面试的面试点,这些点构建了一个完整的知识体系。后面,我会细化里面的知识,如果 大家觉得有问题,请联系我~

这里附上上述的技术知识点相关的几十套腾讯、头条、阿里、美团等公司19年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

Some say it is the primary Android engineers face through?  It scared me!

上述【高清技术脑图】以及【配套的架构技术PDF】可以 加我wx:X1524478394 免费获取

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.

  • Whether you now how levels must continue to learn and no soup, others look effortless, in fact, took a very strong, these four words is my advice! ! ! ! ! ! ! ! !
  • I hope that every effort of life IT engineer, will get what we want, because we are very hard, we deserve.

Guess you like

Origin blog.51cto.com/14332859/2455402