In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 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 what are the relevant knowledge points of the android intermediate and advanced interview questions, 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 learn about it.
1. Activity life cycle?
OnCreate ()-> onStart ()-> onResume ()-> onPause ()-> onStop ()-> onDetroy ()
2. Service life cycle?
There are two ways to start service
One is to start through startService ().
The other is to start it through bindService ().
Their life cycle is different with different startup methods.
Service started by startService ()
The life cycle is like this:
Call startService ()-> onCreate ()-- > onStartConmon ()-- > onDestroy ().
If you start in this way, you need to pay attention to several problems.
First: when we are called through startService, startService () will be called many times, the onCreate () method will only be called once, and onStartConmon () will be called multiple times, and when we call stopService (), onDestroy () will be called, thus destroying the service.
Second: when we start through startService, pass the value through intent, and get the value in the onStartConmon () method, we must first determine whether intent is null.
Bind through bindService (), which binds service
Life cycle:
BindService-- > onCreate ()-> onBind ()-> unBind ()-> onDestroy ()
The advantage of starting service by bindservice is that it is more convenient to operate service in activity. If you want to call it in activity, get the ServiceConnection object in activity, get the class object of the inner class in service through ServiceConnection, and then call the method in the class through this class object. Of course, this class needs to inherit the Binder object.
3. The startup process of Activity (do not answer the life cycle) 4. The registration mode and difference of Broadcast
Extended here: under what circumstances do you use dynamic registration
There are two main ways to register for Broadcast broadcasting.
The first kind is static registration, which can also become a permanent broadcast, which needs to be registered in the Androidmanifest.xml. The broadcast registered in this way is not affected by the life cycle of the page. Even if you exit the page, you can also receive the broadcast. This broadcast is generally used for boot-up, ah, and so on. Because the broadcast in this way of registration is a permanent broadcast, it will take up CPU resources.
The second is dynamic registration, and dynamic registration is registered in the code, this registration method is also called non-resident broadcast, affected by the life cycle, after exiting the page, we will not receive the broadcast, we usually use it to update UI. This registration method has a higher priority. Finally, you need to unbind, or there will be a memory leak.
Broadcasting is divided into orderly broadcasting and disordered broadcasting.
5. The difference between HttpClient and HttpUrlConnection.
Extended here: which request method is used in Volley
First of all, both HttpClient and HttpUrlConnection support Https protocol, both upload or download data in the form of stream, or transmit data in the form of stream, as well as ipv6, connection pool and other functions. HttpClient has a lot of API, so if you want to extend it without breaking its compatibility, it's hard to extend it. That's why Google abandoned this HttpClient directly when it was in Android6.0.
And HttpUrlConnection is relatively lightweight, API is relatively less, easy to expand, and can meet most of the data transmission of Android. A more classic framework, volley, used Android HttpClient before Android 2.3 and HttpUrlConnection after Android 2.3.
6. The difference between java virtual machine and Dalvik virtual machine
Java virtual machine:
1. Java virtual machine is based on stack.
Stack-based machines must use instructions to load and manipulate data on the stack, requiring more instructions.
2. The java virtual machine runs java bytecode.
The java class is compiled into one or more bytecode .class files.
Dalvik virtual machine:
1. The dalvik virtual machine is register-based
2. Dalvik runs a custom .dex bytecode format.
After the java class is compiled into a .class file, all .class files are converted into a .dex file through a dx tool, from which the dalvik virtual machine reads instructions and data.
The constant pool has been modified to use only 32-bit indexes to simplify the interpreter.
4. One application, one virtual machine instance, one process
All android application threads correspond to a Linux thread, all running in their own sandboxie, and different applications running in different processes. Each android dalvik application is assigned a separate linux PID (app_*)
7. Process preservation (immortal process) 8. Explain Context9, understand the relationship among Activity,View,Window 10, four kinds of LaunchMode and their usage scenarios 11, View drawing flow 12, View,ViewGroup event distribution 13, save Activity state
OnSaveInstanceState (Bundle) will be called before the activity goes to the background state, that is, before the onStop () method, and after the onPause method
14. Several animations in Android
Frame animation:
It refers to the animation effect formed by specifying the picture and playback time of each frame in an orderly manner, such as the rhythm bar you want to hear.
Motion tweens:
Refers to by specifying the initial state of View, change time, way, through a series of algorithms to carry out graphic transformation, so as to form animation effects, mainly Alpha, Scale, Translate, Rotate four effects.
Note: it only animates in the view layer and does not really change the properties of View, such as sliding the list and changing the transparency of the title bar.
Attribute animation:
It is only supported in Android3.0, by constantly changing the properties of View and constantly redrawing to form animation effects. Compared to the view animation, the properties of View have really changed. For example, the rotation, magnification and reduction of view.
15. Several ways of cross-process communication in Android
Android cross-process communication, such as intent,contentProvider, broadcast, service, can be cross-process communication.
Intent:
This cross-process approach is not in the form of accessing memory, it requires passing a uri, such as making a phone call.
ContentProvider:
This form is to use the form of data sharing for data sharing.
Service:
Remote services, such as aidl
Broadcast:
Broadcasting includes static broadcast and dynamic broadcast.
16. AIDL understands the principle of 17. Handler.
In Android, the main thread cannot perform time-consuming operations, and child threads cannot update the UI. So there is handler, which is used to communicate between threads.
There are four main objects in the whole process of handler.
Handler,Message,MessageQueue,Looper . When the application is created, the handler object is created in the main thread
We save the message to Message, and handler sends Message to MessageQueue by calling the sendMessage method, and the Looper object keeps calling the loop () method.
Constantly take the Message from the MessageQueue and give it to the handler for processing. So as to realize the communication between threads.
18. Principle of Binder mechanism
In the Binder mechanism of Android system, there are Client,Service,ServiceManager,Binder drivers, in which Client,service,Service Manager runs in user space and Binder drivers run in kernel space. Binder is the glue that binds these four components together, and the core component is the Binder driver. Service Manager provides the function of auxiliary management, while Client and Service realize the communication between Binder driver and the infrastructure provided by Service Manager. The Binder driver provides device file / dev/binder to interact with the user control, and Client and Service,Service Manager communicate with the Binder driver through the corresponding methods of open and ioctl file operation. The interprocess communication between Client and Service is realized indirectly through the Binder driver. Binder Manager is a daemon that manages Service and provides Client with the ability to query the Service interface.
19. The principle of thermal repair
We know that the Java virtual machine-JVM loads the class file of the class, while the Android virtual machine-Dalvik/ART VM loads the dex file of the class, and when they load the class, they all need ClassLoader,ClassLoader to have a child BaseDexClassLoader, and under BaseDexClassLoader there is an array-DexPathList, which is used to store dex files. When BaseDexClassLoader calls the findClass method, it is actually traversing the array, finding the corresponding dex file, and finding it directly. The solution to hotfix is to add the new dex to the collection, and it is in front of the old dex, so it will be fetched first and the return will be returned.
`
20. Android memory leak and management 22. Android UI adaptation
Fonts use sp
Dp, use match_parent,wrap_content,weight more often
Picture resources, the resolution of different pictures, placed in the corresponding folder can be replaced by a percentage.
23. App optimization 21, communication mode between Fragment and Fragment, Activity 24, picture optimization
(1) operate on the picture itself.
Try not to use setImageBitmap, setImageResource, or BitmapFactory.decodeResource to set up a large picture, because after completing the decode, these methods are finally done through the createBitmap of the java layer, which consumes more memory.
(2) the scaling ratio of the image. In SDK, it is recommended that the value is an exponential value of 2. The higher the value, the image is not clear.
(3) for unused pictures, remember to call the recycle () method of the picture.
25. Interaction between HybridApp WebView and JS 26, JAVA GC principle
The core idea of garbage collection algorithm is:
To identify the available memory space of the virtual machine, that is, the object in the heap space, if the object is being referenced, it is called a living object, on the contrary, if the object is no longer referenced, it is a garbage object, and the space it occupies can be reclaimed for redistribution. The selection of garbage collection algorithm and the reasonable adjustment of garbage collection system parameters directly affect the performance of the system.
27 、 ANR
The full name of ANR is Application Not Responding, that is, "application is not responding". When the operation cannot be processed by the system for a period of time, the ANR dialog box shown above will pop up at the system level.
Cause:
(1) unable to respond to user input events (such as keyboard input, touch screen, etc.) within 5 seconds.
(2) BroadcastReceiver cannot be finished within 10 seconds
(3) Service cannot end within 20s (low probability)
Solution:
(1) do not do time-consuming operations in the main thread, but should be implemented in child threads. Do as few creation operations as possible in onCreate () and onResume ().
(2) applications should avoid time-consuming operations or calculations in BroadcastReceiver.
(3) avoid launching an Activity in Intent Receiver, as it creates a new screen and grabs focus from the program the current user is running.
(4) service runs on the main thread, so time-consuming operations in service must be placed in child threads.
28. Design pattern 29, Xutils, OKhttp, Volley, Retrofit vs. 30, MVP,MVC,MVVM31, JNI
(1) install and download Cygwin and download Android NDK
(2) the design of JNI interface in ndk project.
(3) the local method is implemented by using Cramble +.
(4) JNI generates dynamic link library .so file
(5) copy the DLL to the java project, call it in the java project, and run the java project.
32. The difference between RecyclerView and ListView
RecyclerView can achieve the effect of ListView,GridView as well as waterfall flow. You can also set the scrolling direction of the list (vertical or horizontal)
The reuse of view in RecyclerView does not require developers to write their own code, and the system has helped to package it.
RecyclerView can perform a local refresh.
RecyclerView provides API to realize the animation of item.
In terms of performance:
If you need to refresh data frequently and add animation, RecyclerView has a great advantage.
If it is only shown as a list, there is not much difference between the two.
These are all the contents of the article "what are the intermediate and advanced interview questions in android". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.