Home  >  Article  >  Web Front-end  >  Share Android interview experience [Selected]

Share Android interview experience [Selected]

藏色散人
藏色散人forward
2020-07-31 15:09:554863browse

Recommended: "2020 Android interview questions summary [Collection]"

I have participated in interviews with many companies since the beginning of the year, and also received several Offers from giants and other companies. Summarizing the experience is also a review and summary of the past.

1. Resume

There are a lot of guidance on programmer resumes on the Internet, so I won’t repeat them here. You can search for the summaries of other experts on the Internet and modify them based on your own situation. I have a few suggestions:

1. Try not to be fancy. Programmers are different from designers or product operators. The decision on whether our resume is successful or not lies with the technical interviewer, and what they value is Description of your project experience content and technology.

2. In the skill description, try to only write what you know and understand deeply. You can add some new technologies or popular frameworks appropriately, but this needs to be understood. If you haven’t had time to read the source code, you can take a look at what the experts have said about it. There are a lot of summaries on the Internet.

3. Try to add keywords to the project experience, such as what technology was used, what design patterns were used, optimized data comparison, extended summary, etc. Instead of simply introducing the content of the project (that is the product manager's description), for example, performance optimization is divided into UI performance optimization, memory optimization, database optimization, network optimization, power consumption optimization, etc. It can be described from the following aspects: 1. How to discover the problem, 2. How to solve the problem, 3. Comparison of the solution effects. To give a simple example - UI optimization, you can look at what problems occur in the UI (stuck and not smooth), how to find the problem (mobile developer permissions>GPU over-drawing found layer problems, TraceView CPU usage analysis), how to solve the problem ( Lowering the level, problems with custom View drawing, etc.). Compare the performance again after solving the problem.

2. Skill reserve

(1) Java

1. What is the difference between HashMap and Hashtable?

You must read the source code for this! Look at the source code! Look at the source code! If you really can’t stand it, you can go online and read other people’s analysis. A brief summary:

1. HashMap supports null Key and null Value; Hashtable does not allow it. This is because HashMap performs special processing on null, sets the hashCode value of null to 0, and stores it in the 0th bucket of the hash table.

2.HashMap is non-thread-safe. The method to implement thread-safety in HashMap is Map map = Collections.synchronziedMap(new HashMap()); Hashtable is thread-safe.

3.The default length of HashMap is 16. The expansion is 2 times the original; the default length of Hashtable is 11, and the expansion is the original 2n 1

4.HashMap inherits AbstractMap; Hashtable inherits Dictionary

extension, HashMap compares with ConcurrentHashMap, HashMap compares with SparseArray , LinkedArray vs. ArrayList, ArrayList vs. Vector

2. Java garbage collection mechanism

Need to understand JVM, memory division - method area, memory heap, virtual machine stack (thread private), local methods Stack (thread private), program counter (thread private), understand the recycling algorithm - mark and clear algorithm, reachability analysis algorithm, mark and sort algorithm, copy algorithm, generational algorithm, understand the advantages and disadvantages.

For details, you can read what other students wrote and click to open the link

3. Class loading mechanism

This can be combined with hot repair for an in-depth understanding. Click to open the link

4. Threads and thread pools, concurrency, locks and a series of issues

This can be expanded. How to implement a thread pool yourself?

5. Understanding HandlerThread and IntentService

6. The difference between weak reference and soft reference

7. What is the difference between int and Integer

Mainly evaluate value transfer and reference passing issues

8. Handwritten producer/consumer model

(2) Android

1. Android startup mode

Need to understand Activity Stack and taskAffinity

1.Standard: System default, one more Activity instance is started each time

2.SingleTop: The top of the stack is reused. If it is at the top of the stack, the life cycle will not go through onCreate( ) and onStart(), onNewIntent() will be called, which is suitable for pushing message details pages, such as news push details Activity;

3.SingleTask: reuse in the stack, if it exists in the stack, all activities on it All are popped from the stack so that they are at the top of the stack. The life cycle is the same as SingleTop. The app homepage basically uses this

4.SingleInstance: This is the SingleTask enhanced version. The system will open a separate stack for the Activity to be started. It is the only one in this stack. It is suitable for newly opened activities and apps that can be opened independently, such as the system alarm clock and WeChat’s video chat interface. I don’t know if it is the same. If you know it, let me know. Thank you!

In addition, SingleTask and SingleInstance seem to affect the callback of onActivityResult. Please search for specific issues, so I won’t elaborate.

Intent also requires further understanding of the usage and functions of Action, Data, and Category, as well as commonly used

Intent.FLAG_ACTIVITY_SINGLE_TOP
Intent.FLAG_ACTIVITY_NEW_TASK
Intent.FLAG_ACTIVITY_CLEAR_TOP

, etc. Please take a look at the source code for details.

2. View drawing process

ViewRoot
-> performTraversal()
-> performMeasure()
-> performLayout()
-> perfromDraw()
-> View/ViewGroup measure()
-> View/ViewGroup onMeasure()
-> View/ViewGroup layout()
-> View/ViewGroup onLayout()
-> View/ViewGroup draw()
-> View/ViewGroup onDraw()

Let’s take a look at the invalidate method. There are 4 parameters, and what is the difference between those without parameters? requestLayout triggers measure and layout, how to implement local re-measurement , to avoid the global remeasurement problem.

3. Event distribution mechanism

-> dispatchTouchEvent()
-> onInterceptTouchEvent()
-> onTouchEvent()
requestDisallowInterceptTouchEvent(boolean)

Also the order of onTouchEvent(), onTouchListener, and onClickListener

4. Message distribution mechanism

This test is very common. Be sure to look at the source code, there is not much code. Let’s look at it with a few questions:

1. Why does a thread have only one Looper and only one MessageQueue?

2. How to get the Looper of the current thread? How is it achieved? (Understanding ThreadLocal)

3. Can any thread instantiate Handler? Are there any constraints?

4.Looper.loop is an infinite loop. If it cannot get the Message that needs to be processed, it will block. So why does it not cause ANR in the UI thread?

5.How does Handler.sendMessageDelayed() implement delay? Combined with Looper.loop() loop, Message=messageQueue.next() and MessageQueue.enqueueMessage() analysis.

5. AsyncTask source code analysis

Analysis of advantages and disadvantages, there are a lot of them on the Internet, so I won’t repeat them.

6. How to ensure that Service is not killed? How to ensure that the process is not killed?

These two questions were asked by 3 companies during my interview.

7. Binder mechanism, process communication

The bottom layer of process communication used by Android is basically Binder, AIDL, Messager, broadcast, and ContentProvider. I don’t understand it very deeply. At least how to use ADIL and how to use Messager can be written and read. In addition, serialization (Parcelable and Serilizable) needs to be compared. In this regard, you can read the android art development exploration book by Ren Yugang.

8. Dynamic permission adaptation issues and skin-changing implementation principles

Let’s take a look at Hongyang’s blog post in this regard

9. SharedPreference principle, can it be cross-process? How to achieve?

(3) Performance optimization issues

1. UI optimization

a. Reasonably choose RelativeLayout, LinearLayout, FrameLayout. RelativeLayout will make the sub-View call onMeasure twice, and the layout When it is relatively complex, onMeasure is relatively complex and inefficient. LinearLayout will also let the sub-View call onMeasure twice when weight>0. LinearLayout weight measurement distribution principle.

b. Use the tag dcf91641426a34cf32ecc36140f28baf76deed1c218ccc4d4a17740bf4fefa6ae7ce6ff74a06bd752b5697fed60b5487

c. Reduce the layout level, you can use mobile developer options>GPU transition drawing view, general level control Within 4 layers, if it exceeds 5 layers, you need to consider whether to rearrange the layout.

d. When customizing View, rewrite the onDraw() method and do not create new objects in this method, otherwise it will easily trigger GC and lead to performance degradation

e. Reuse is required when using ListView contentView, and use Holder to reduce findViewById to load View.

f. Remove unnecessary background, getWindow().setBackgroundDrawable(null)

g. Use TextView's leftDrawabel/rightDrawable instead of ImageView TextView layout

2. Memory optimization

Mainly to avoid performance degradation caused by OOM and frequent triggering of GC

a.Bitmap.recycle(),Cursor.close,inputStream.close()

b. Mass loading When Bitmap, load Bitmap according to View size, choose inSampleSize, RGB_565 encoding method appropriately; use LruCache cache

c. Use static internal class WeakReference instead of internal classes, such as Handler, thread, AsyncTask

d .Use thread pool to manage threads to avoid new threads

e. Use singleton to hold Context and remember to release it, or use global context

f. Pay attention to releasing static collection objects

g. Attribute animation causes memory leaks

h. When using webView, it needs to be removed and destroyed in Activity.onDestory, webView.removeAllViews() and webView.destory()

Prepare: Use LeakCanary to detect memory leaks

3. Response speed optimization

If Activity cannot respond to screen touch events and keyboard input events within 5 seconds, ANR will occur, and if BroadcastReceiver cannot respond to screen touch events and keyboard input events within 10 seconds, ANR will occur before the operation is performed within 20 seconds. In order to avoid ANR, you can start a sub-thread to perform time-consuming operations, but the sub-thread cannot update the UI, so the Handler message mechanism, AsyncTask, and IntentService are required for thread communication.

Note: When ANR occurs, adb pull data/anr/tarces.txt combined with log analysis

4. Other performance optimization

a. Use static final modification for constants

b. Use SparseArray instead of HashMap

c. Use thread pool to manage threads

d. Use regular for loop for ArrayList traversal, and use foreach for LinkedList

e. Don’t Excessive use of enumerations, which occupy larger memory space than integers

f. Prioritize StringBuilder and StringBuffer for string splicing

g. Database storage uses batch insert transactions

(4) Design Pattern

1. Singleton pattern: There are several writing methods. It is required to be able to write by hand and analyze the pros and cons. Volatile is generally used in double check locks, and the principle of volatile needs to be analyzed

2. Observer mode: It is required to be able to write by hand. Some interviewers will ask you if you have used it in the project? If you really haven’t heard of it, you can talk about EventBus, which uses the observer mode

3. Adapter mode: It is required to be able to write by hand. Some companies will ask what is the difference between it and the decorator mode and the proxy mode?

4. Builder mode Factory mode: It is required to be able to write by hand

5. Strategy mode: This question is relatively rare, but some e-commerce people will ask it.

6.MVC, MVP, MVVM: Compare the similarities and differences, just choose one you are good at and focus on it

(5) Data structure

1. What are the differences in usage and principles between HashMap, LinkedHashMap, and ConcurrentHashMap? Many companies will test the HashMap principle and make some extensions through it, such as China's 1.3 billion population age Sorting problem, the age corresponds to the number of buckets, the same age and the same hash problem are similar.

2. Compared with ArrayList and LinkedList, this one is relatively simple.

3. I have also been tested on balanced binary trees, binary search trees, and red-black trees.

4.Set principle, this is somewhat similar to the HashMap test. The test is related to the hash algorithm. I was asked about the commonly used hash algorithm. HashSet uses HashMap

internally (6) Algorithm

Algorithm is mainly used to test questions. Go to LeetCode and Niuke.com to brush up.

(7) Source code understanding

Open source frameworks are more or less used in projects. Many companies like to ask about the principles and whether they have seen the source code, such as the network framework Okhttp, which is the most commonly used , Retrofit RxJava is also very popular now.

1. Network framework library Okhttp

Be sure to read the okhttp source code. Remember several key classes in it, as well as connection pools and interceptors. You need to understand them. I was asked how to add headers to the URLs of certain specific domain names. If the code is encapsulated by yourself, it can be solved in the encapsulated Request, or you can add an interceptor and do it through the interceptor.

Recommend a good article explaining Okhttp

2. Message notification EventBus

1. EventBus principle: It is recommended to look at the source code, there is not much. Internal implementation: Observer pattern Annotation Reflection

2. Can EventBus cross-process? Method to replace EventBus (RxBus)

3. Image loading library (Fresco, Glide, Picasso)

1. Which image loading library was selected in the project? Why choose it? Are other libraries bad? The difference between these libraries

2. Choose the principle of the image library in the project, such as Glide (LruCache combined with weak references), then the interviewer will ask about the principle of LruCache, and then ask about the principle of LinkedHashMap, so layer by layer People ask questions, so if you see something you don’t understand, I suggest you go in and take a look. For example, Fresco is used in the MVC design pattern, and shared memory is used below 5.0. How to use shared memory? How to achieve rounded corners in Fresco? How to configure cache in Fresco?

4. Message Push

1. Did you do the message push in the project yourself or did you use a third party? Like the aurora. Have you used any others? What are the advantages and differences between these companies, and why did you choose them?

2. What is the principle of message push? How to implement heartbeat connection?

5. TCP/IP, Http/Https

If the resume says that you are familiar with the TCP/IP protocol and Http/Https protocol, you will definitely be asked, and I will verify it. . Generally, I will answer the network layer relationship, the difference between TCP and UDP, TCP three-way handshake (be sure to explain clearly, you need to be familiar with the flag bits such as SYN, ACK and the message structure), and wave four times. Why three handshakes? DDoS attack. Why do we shake hands three times and wave four times? Http message structure, what is the process of a network request? What is the difference between HTTP and HTTPS? How does SSL/TLS perform an encrypted handshake? How to verify the certificate? What are symmetric encryption algorithms and asymmetric encryption algorithms? Choose a familiar encryption algorithm and briefly introduce it? How does DNS resolution work?

6. Hot update, hot repair, plug-in (this area is more demanding and generally senior engineers need to understand it)

Understand classLoader

7. New technology

RxJava, RxBus, RxAndroid, when interviewing the company you want to go to, you can decompile their packages and see if they are used. If they are used, you will inevitably ask questions during the interview. If not, how can you It can be ignored, but students with a strong desire to learn can take a look at it. It is a relatively popular framework.

Retrofit, students who are familiar with okhttp suggest taking a look. I heard that it is very cool to combine it with RxJava.

Kotlin

3. Finally

The internal referral method is the first choice for resumes, which is fast and efficient! Then you can take a look at the hook, the boss, Maimai, and the street. It says on your resume that if you are familiar with any technology, you must be familiar with it, otherwise it will not be embarrassing when asked! What kind of projects have you done? Even if the project size is not large, you must be familiar with the implementation principles! It's not the part you're responsible for. You can also look at how your colleagues implement it. What would you do if it were you? What you have done and what you know is a matter of breadth, depending on the content of the project. But what you have done and what state you have reached are in-depth issues related to your personal learning ability and attitude towards problem-solving. Large companies look at depth, small companies look at breadth. You know what you know when interviewing with big companies, but whether you know what they use in interviews with small companies is the job matching degree.

After selecting a few companies you want to go to, first go to some small companies to practice and learn interview skills. In summary, you can also be familiar with the interview atmosphere. You can talk to colleagues or product PKs. It’s very clear and clear. It’s really different when you get to the scene. How to describe everything you do is definitely an academic question!

Be sure to be polite during the interview! Even if you feel that the interviewer does not respect you and often interrupts your explanations, or you feel that he is not as good as you and the questions he asks lack professionalism, you must respect him because he is the one who chooses you now and waits for you to get the offer. It's you who chooses him in the end.

In addition, you must be slow to describe the problem! Don't talk a lot at once. Slowness shows that you are calm and confident, and you still have time to reflect on your ideas on how to talk better next. Nowadays, development relies too much on IDE, so there will be a disadvantage. When we explain it in the interview, it is easy not to know how to pronounce a certain method. This is a flaw... So we must know the common key class names. , method names, and keywords should be read accurately. Some interviewers will be impatient and say, "Which one are you talking about?" At this time, we will easily get confused. Correct pronunciation, calm description, and a nice voice are definitely a plus!

The most important thing is mentality! Mentality! Mentality! Say important things three times! The interview time is very short, and it is relatively unrealistic for the other party to find out your background in a short period of time. Therefore, sometimes it is also based on eyesight. This is still an era of face.

I hope everyone can find a job that is suitable and satisfactory to them! fighting!

The above is the detailed content of Share Android interview experience [Selected]. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jianshu.com. If there is any infringement, please contact admin@php.cn delete