In the Android development interview, what questions do interviewers like to ask most?

Author: Xiao Xie

"What quality Android interviews have you had?"

[External link image transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the image and upload it directly (img-3Pc1xZw5-1691675604271)(//upload-images.jianshu.io/upload_images/24388310-aa3c732481d0749f.png?imageMogr2 /auto-orient/strip|imageView2/2/w/1200)]

This is a hot topic I saw on Zhihu a few days ago. After seeing it, I became interested and tried to scroll down. I saw that the answers below were all sharing and telling about my interview experience, interview feelings and Reflections and conclusions after the interview. Let's just say it's wonderful.

But seeing that the time for asking questions was 3 years ago, why is there still a heat wave today after 3 years?

Thinking about this question, I read the Q&A in its entirety. I thought about the question time, and then thought about the push time I received. Only then did I realize that the "golden nine silver ten job-hopping golden period" is approaching, and most programmers are eager to try, so the question and answer three years ago once again set off a heat wave.

Think about it, I have been in the Internet industry for three years, and I have interviewed no less than ten major companies in the past few years. There are also 3 companies that got the offer, including Xiaomi, Netease, and Sina. Now they are fishing in ByteDance. If you have a chance, let’s join together! The average level of the offers I got is around 24K-27K (working for 1-2 years), and I took the opportunity of question and answer to do a wave of interview reviews.

1. Company A

1. Introduce the project

I made a news app before, which is equivalent to a low imitation of today's headlines!

basic skills:

  • Welcome page loading (3s, click to skip) - Activity related

  • User registration/login - SQLite application

  • Horizontal sliding list to display news categories - application of TabLayout, ViewPager, FragmentPagerAdapter

  • Bottom menu bar switching - Fragment application

  • Home page (display news list) - ListView

  • Settings (exit the application, log out, clear the cache) - Activity management, SharePreference

  • My (account security, news favorites) - SQLite

  • News list pull down, slide up to achieve refresh - custom ListView

  • Collect news one by one, delete news - SharePreference

  • Imitation UI interface - application of various controls

  • Click to view news details - WebView

  • User interface avatar replacement function - Android runtime permissions, multimedia, Content Provider

2. Briefly talk about the Activity life cycle?

The following figure is the Activity state transition diagram (note that in the figure, the process of state transition is executed in the box, not the state. As mentioned above, there are only three states: RUNNING / PAUSED / STOPPED.)

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-vJsbyXJt-1691675604273)(//upload-images.jianshu.io/upload_images/24388310-a2e09c41ef074d05?imageMogr2/auto -orient/strip|imageView2/2/w/795)]

3. Briefly describe the RecyclerView caching mechanism?

RecyclerView can be said to have replaced listview in Android applications. Its flexible, assembled settings, and multi-caching mechanism can adapt to the various needs of multi-list in Android development.

For the caching mechanism of RecyclerView, I have always wanted to think a little bit more. To put it simply, RecyclerView has two layers of caching support in comparison with listview caching mechanism. Listview is a two-level cache, and RecyclerView is a four-level cache (of course, in most cases. is the L3 cache).

4. In a listview, each item has an animation (gif) view, when I click the button in the item, the animation (gif) plays. Sliding the listview when there is animation playing, occasionally the event of item misplacement will occur. what is the reason?

This is a problem of item reuse, and the image is misplaced due to asynchronous loading

5. When the Activity has multiple Handlers, will the Message message be confused? How to distinguish which Handler handles the current message?

There will be no confusion, which Handler sends the message, and it will be processed by this handler at that time. When sending a message, it will bind the target, which is the Handler itself. When the handler needs to call dispatchMessage(msg) to process the message, the Handler is the handler bound when sending the message.

No matter which method is used to send the message, it will eventually call enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) to send the message

private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
        msg.target = this;
        if (mAsynchronous) {
            msg.setAsynchronous(true);
        }
        return queue.enqueueMessage(msg, uptimeMillis);
    }

This here is the current handler. When looking at the need for a Handler to process a message, which handler is taken, the main source code is posted below.

public static void loop() {
  ......
        for (;;) {
            Message msg = queue.next(); // might block
            if (msg == null) {
                // No message indicates that the message queue is quitting.
                return;
            }

            // This must be in a local variable, in case a UI event sets the logger
         ......
            if (traceTag != 0 && Trace.isTagEnabled(traceTag)) {
                Trace.traceBegin(traceTag, msg.target.getTraceName(msg));
            }

            final long dispatchStart = needStartTime ? SystemClock.uptimeMillis() : 0;
            final long dispatchEnd;
            try {
                msg.target.dispatchMessage(msg);
                dispatchEnd = needEndTime ? SystemClock.uptimeMillis() : 0;
            } finally {
                if (traceTag != 0) {
                    Trace.traceEnd(traceTag);
                }
            }
           ......

            msg.recycleUnchecked();
        }
    }

This is part of the code when looping messages. The message processing code is msg.target.dispatchMessage(msg); where the target is the handler that sent the message at that time.

2. Company B

1. Introduce the project

just said, no more introduction

2. Tell me about your understanding of strong references, weak references, and soft references in Java

Strong reference: This kind of reference is the type of reference that we frequently use in normal times. The JVM defaults to this type of reference. For example, A a = new A(), this is a strong reference;

Under this type, when the memory space is insufficient, the JVM would rather OOM, causing the program to abort and exit abnormally, and will not recycle it at will. Only when the object is not referenced, the JVM will recycle it.

Soft reference: We can use this kind of reference like this, SoftReference sr = new SoftReference(new A()); You can use sr.get() to get this object, this type of reference object, if the JVM has enough memory He will be recycled; if the JVM runs out of memory, these objects will be recycled. This reference type is suitable for use as a cache.

Weak reference: This kind of reference can be used here, WeakReference wr = new WeakReference(new A()); and then use wr.get() to get this object; this kind of reference type object has more With a shorter life cycle, when the garbage collector scans the memory area of ​​the JVM and encounters objects of this type of reference, these objects will be recycled regardless of whether the current memory is sufficient.

3. What is deadlock? What are the necessary conditions? How to avoid it?

  • A deadlock is a situation in which multiple processes wait indefinitely for resources held by others. When two or more processes request the use of multiple mutually exclusive resources at the same time, deadlock may result.

  • Mutually exclusive conditions: that is, only one process can use resources at a time, and other processes cannot access resources that have been allocated to other processes

  • Hold and wait: When a process waits for another process to release a resource, it is known to hold the resource

  • Non-preemptive: other processes cannot forcibly occupy resources that have been allocated to the process

  • Circular waiting: There is a closed chain, and the process in the chain occupies at least one resource required by the next process in the chain

Deadlock avoidance:

  • Mutex prevention: Impossible to prohibit

  • Prevent possession and waiting: Let the process apply for all resources at one time.

  • Prevention of non-preemption: (1) When the resource-occupied process further applies for resources, it refuses, and then forcibly releases the currently occupied resources. You can reapply if necessary. (2) When a process requests a resource occupied by another process, the operating system can preempt the resource-occupied process. Request to release resources. The second option is only available if any two processes have different priorities.

  • Preventing circular waits: defining a linear sequence of resource accesses

4. The difference between TCP and UDP

  1. Connection based vs. connectionless.

  2. TCP requires more system resources, and UDP requires less.

  3. UDP program structure is relatively simple.

  4. Stream mode (TCP) and datagram mode (UDP).

  5. TCP guarantees data correctness, and UDP may lose packets.

**5. Algorithm question:**Given a non-empty string s and a dictionary wordDict containing a non-empty word list, determine whether s can be split into one or more words that appear in the dictionary.

Android

1. What methods need to be rewritten for custom View?

(Combined with actual needs, if you need to slide, rewrite onTouchEvent, and if you need to control your own layout, rewrite onMeasure, onLayout)

2. How to optimize the layout?

3. Handler message mechanism

4. Talk about your understanding of UI optimization

3. Company C

1. Introduce the project

just said, no more introduction

2. Have you ever learned about plug-in? What is the difference between plug-in and componentization?

3. When to use Application Context and when to use Activity Context

4. Must the UI be updated in the main thread? Can it be updated in the child thread?

5. How is kotlin compatible with Java?

After so many replays, in fact, careful friends can find that Dachang interviews pay more attention to Java foundation and Android foundation, so it is necessary to sort out a wave of knowledge before the interview.

After combing the knowledge, I also prepared a lot of learning documents such as e-books and interview notes. These notes perfectly summarize various knowledge points (including a lot of content: Android basics, Java basics, Android source code related analysis, common Some principle questions, etc.):https://qr18.cn/CgxrRy

Guess you like

Origin blog.csdn.net/weixin_61845324/article/details/132219366