Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the important interview questions in Android interview?

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, the editor will share with you the relevant knowledge of the important interview questions in the Android interview. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Talk about the understanding of java polymorphism, inheritance, and interface.

The definition of polymorphism

Different types of objects make different responses or actions to the unified function.

Action

Mainly to eliminate the coupling between classes, strong flexibility, conducive to the writing and modification of the code. Especially when dealing with a large number of operations and operations, you can flexibly simplify, replace or modify the code!

Three necessary conditions

1. A stool (inheriting extends)

2. Rewrite

3. The parent class reference points to the subclass object

For example

* * Test results:

The principle of oKhttp

1. Synchronous and asynchronous:

1. Dispatcher is used asynchronously to dispatch requests stored in Deque to individual threads in the thread pool for execution.

two。 When the task is executed, regardless of whether there is an exception or not, the finally code snippet will always be executed, that is, the finished function of Dispatcher will be called, which takes the cache queue forward after removing the running task Call from the queue runningAsyncCalls.

two。 Connection pooling:

1. A Connection encapsulates a socket,ConnectionPool that stores all the Connection,StreamAllocation is a unit of reference count.

two。 When a request gets a Connection, it passes in a list of StreamAllocation with a weak reference in the StreamAllocation,Connection, and the Connection,StreamAllocation is added each time the upper application references it. On the other hand, if the upper application is not in use, one will be deleted.

There is a background task in 3.ConnectionPool that periodically cleans up the Connection whose StreamAllocation list is empty. 5 minutes to maintain 5 socket

3. Select a route and establish a connection

1. There are two ways to choose a route:

3. Proxy benefits: HTTP agents help you make DNS queries on remote servers, which can reduce DNS hijacking.

1. If there is no proxy, then use DNS locally to find ip. Note that the result is an array, that is, a domain name has multiple IP, which is the source of automatic reconnection.

two。 Proxy HTTP: set the ip of socket as the ip of proxy address, and the port of socket as the port of proxy address

two。 Establish a connection

1. If a connection already exists in the connection pool, get the RealConnection from it. If not, proceed to the next step.

two。 According to the selected route (Route), call Platform.get (). ConnectSocket to select the best socket library under the current platform Runtime for handshake

3. Put the established RealConnection into (put) the connection pool cache

4. If a TLS exists, make a secure handshake with the certificate based on the SSL version

5. Construct HttpStream and maintain the socket connection just now, and the pipeline is established.

4. Responsibility chain mode: caching, retry, establishing connection and other functions exist in the interceptor related to network requests, mainly network request optimization. Problems encountered in network requests

The problem of thread synchronization, common thread synchronization

1.sycn: ensures atomicity, visibility and order

two。 Lock: ensures atomicity, visibility and order

1. Spin lock: allows a thread to execute an empty loop without being suspended when the lock is not acquired.

1. Advantages: threads are less likely to be suspended and thread execution is more consistent. For concurrent threads where lock competition is not very fierce and lock occupancy time is very short.

two。 Disadvantages: too much CPU time is wasted, and a thread tries to acquire a spin lock twice in a row, causing a deadlock

two。 Blocking locks: threads that do not get the lock wait or hang, Sycn, Lock

3. Reentrant lock: a thread can acquire the lock multiple times, Sycn, Lock

4. Pessimistic lock: every time I go to get the data, I think someone else will modify it, so it will block all other threads such as Sycn and Lock.

5. Optimistic lock: every time you go to get the data, you think that others will not change it, so you will not lock it, but when you update it, you will judge whether others have updated the data during this period. You can use mechanisms such as version number. Cas

6. Display lock and built-in lock: display lock is defined by Lock, built-in lock is defined by synchronized.

7. Read-write locks: to improve performance, Java provides read

3.volatile

1. It can only guarantee visibility, not atomicity.

two。 There are three steps in the self-increment operation, and there will be problems with multi-threaded writing.

4.cas

1. Operation: memory value V, the old expected value A, the value B to be modified, if and only if the expected value An and memory value V are the same, change the memory value to B and return true, otherwise do nothing and return false.

two。 Explanation: the local copy is A, the shared memory is V, and thread A modifies V to B. At some point, thread A wants to change V to B. if An and V are different, it means that another thread is modifying V, which means that the modification has failed, otherwise it means that no other thread has modified it, then change V to B.

3. Limitation: if V is modified to V1 and then changed to V, cas does not recognize the change and still thinks that no other thread is modifying V, then there will be a problem

4. Limitation resolution: bring V with the version.

5. What's going on with thread unsafety:

1. One thread writes, and when multiple threads read, it will cause them to read in the middle of writing.

two。 Multithreaded writing will result in dirty data

Asynctask is related to thread pool and GC (how to determine which memory is the GC,GC algorithm)

1.Asynctask: asynchronous task class, single thread thread pool + Handler

two。 Thread pool:

1.ThreadPoolExecutor: through Executors, you can construct a single thread pool, a fixed number of thread pools, and a fixed number of thread pools.

2.ScheduledThreadPoolExecutor: you can defer calling threads or repeatedly schedule threads. 3.GC related: important

1. Search algorithm: 1. Reference count

two。 Graph search, reachability analysis

two。 Recovery algorithm: 1. Tag cleanup replication: for youth

two。 Marking and finishing: for old times

3. Heap partition: 1. Eden 80%, survivor1 10%, survivor2 10% in Youth District

two。 Senile area

4. Virtual machine stack partition:

1. Local variable scale

two。 Operand stack

3. Dynamic link

4. Method returns the address

5.GC Roots:

1. Objects referenced in the virtual machine stack (local variables in the stack frame)

two。 Objects referenced by static properties of a class in the method area

3. Objects referenced by constants in the method area

4. Objects referenced by JNI in the local method stack

The java class loading process:

1. Loading timing: before creating instances, accessing static variables or methods, reflecting, loading subclasses

two。 Verify: verify the correctness of file formats, metadata, bytecodes, and symbol references

3. Load: get the file byte stream according to the full class name, convert the byte stream into a static storage structure and put it into the method area, generate a class object

4. Prepare: allocate memory for static variables on the heap

5. Parsing: converting symbolic references in constant pools to direct references

6. Initializing: initializing static variables

Mvc 、 mvp 、 mvvm:

1.mvc: data, View, and Activity,View feed back the operation to Activity,Activitiy to get the data, and the data is refreshed to View through the observer mode. Circular dependence

1.Activity is heavy and difficult to unit test

Serious coupling between 2.View and Model

2.mvp: data, View, and Presenter,View give the operation to Presenter,Presenter to get the data, and when the data is obtained, it is returned to Presenter,Presenter to refresh the View. PV,PM two-way dependence

1. Interface explosion

2.Presenter is very heavy.

3.mvvm: data, View, ViewModel,View will operate to ViewModel,ViewModel to get data, the data and interface are bound, and the data update interface is updated.

1.viewModel 's business logic can be tested separately.

two。 A view corresponds to a viewModel business logic can be separated, there will be no omnipotent class

3. The data is bound to the interface, so you don't have to write junk code, but it's uncomfortable to reuse.

With the formation of ANR, what is the time limit for ARN to appear on each component?

1. As long as the operation of the main thread is time-consuming, it will ARN such as io

The 2.broadcast timeout is 10 seconds. The unresponsive timeout of the key press is 5 seconds. The unresponsive timeout of the foreground service is 20 seconds, and the background service is 200 seconds.

The difference between Serializable and Parcelable

1.P consumption of memory is small

two。 P is used in S program for network transmission.

3.s it is convenient to persist data

4.s using reflection is easy to trigger garbage collection is slow.

Brief introduction of Sharedpreferences Source Code

1. The xml key-value pair stored on the hard disk will have performance problems if there is too much data.

2.ContextImpl records important data of SharedPreferences, file paths and key-value pairs of instances.

3. Before the xml file is fully loaded into memory, the read operation is blocked, and after the xml file is loaded into memory, the data in memory is read directly.

4.apply has no return value because it is asynchronous. Commit is synchronous and has a return value to know whether the modification has been submitted successfully.

5. When submitting commit concurrently, you need to wait for the commit data being processed to be updated to the disk file before continuing to execute, thus reducing the efficiency; while apply is only atomic update to memory, and then calling the apply function will directly overwrite the previous memory data, improving a lot of efficiency to a certain extent. 3.edit () creates a new EditorImpl object every time.

With the formation of ANR, what is the time limit for ARN to appear on each component?

1. As long as the operation of the main thread is time-consuming, it will ARN such as io

The 2.broadcast timeout is 10 seconds. The unresponsive timeout of the key press is 5 seconds. The unresponsive timeout of the foreground service is 20 seconds, and the background service is 200 seconds.

Apk slimming down:

1.classes.dex: optimize the file by deleting unnecessary jar packages and code through code confusion

two。 Resource files: scan for static resources that are not used in the code through the Lint tool

3. Image resources: use tinypng and webP. Here is a detailed description of the optimization scheme of image resources, vector graphics.

4.SO files will be removed. At present, mainstream app generally puts only one so package of arm.

These are all the contents of the article "what are the important interview questions in the Android interview?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report