If there is any flaw or mistake in the article, please comment on it and I will correct it in time.
If you think this article is good, please give it a thumbs up and hope it helps
1. To make a ListView as smooth as possible, how do you usually optimize in your work?
Hierarchy Viewer 1). Hierarchy Viewer 1). Hierarchy Viewer 1). From a visual point of view to intuitively obtain the UI layout design structure and various attributes of information to help us optimize the layout design 2). Use the Debug help to observe invalidate and requestLayout operations on specific UI objects. 2. Reuse convertView, using ViewHolder 3. Asynchronously load 4 when there is an image in item. When loading fast, do not load pictures 5. Realize paging loading of dataCopy the code
2. How much do you know about Android security issues?
Error exporting component 2. Lax parameter verification 3.WebView introduces various security problems and JS in WebView 4. 5. Store key information in plain text 6. Use HTTPS incorrectly 7. Privilege abuse, memory leak, debug signatureCopy the code
3. What are symmetric encryption and asymmetric encryption in the way Android interacts with the server?
Symmetric encryption: just use the same key to encrypt and decrypt data are, asymmetric encryption algorithms are DES: use different key encryption and decryption, and the service side agreement before I can send data generated by the public and private keys, the use of public key encryption of data You can use the decrypted, conversely, data encrypted with the private key can use public key to decrypt. Algorithms include RSA,SSH and SSL classical symmetric encryptionCopy the code
4. Is the onCreate callback for the Service in the UI thread?
Callbacks in the Service lifecycle, like any other application component, run in the main thread and can affect your UI operations or block other things in the main thread (especially when you bind a Service).Copy the code
5. Please introduce the internal application of AsyncTask and its application scenario.
AsyncTask is also handled internally by a Handler mechanism, but Android provides an execution framework to provide thread pools to perform tasks. Due to the size of the thread pool, AsyncTask should only be used to perform short tasks, such as Http requests. Massive downloads and database changes are not applicable to AsyncTask, because the thread pool will be blocked and there will be no threads to perform other tasks, which will happen Problem with AsyncTask not executing at all.Copy the code
6. What is your understanding of binder mechanisms?
Binder is an IPC mechanism for process communication. The Java layer uses AIDL tools to implement interfaces and generate communication codeCopy the code
7. What are the implementation methods of interprocess communication in Android?
Intents provide a Service to handle the connection between the client (active) and the server (passive). Intents provide a Service to connect with the client (active) Similar to BroadcastReceiver, a Service can also access data in other applications, but the difference is that Content Provider A Service that can communicate across processes is called an AIDL ServiceCopy the code
8. Introduce the basic process of implementing a custom View
1. Customize View attributes and compile the attr. XML file 2. 3. Get our custom properties in the View constructor and read them in the custom control 4. Rewrite onMesure (you also need to rewrite onLayout if you want to customize ViewGroup) 5. Overwrite onDraw (if you want to customize ViewGroup you don't need to overwrite this item)Copy the code
9. What are the implementation methods of Android multithreading?
Threads and AsyncTasks Threads can share message processing queues with loops and handlers. Asynctasks can be used as Thread pools to process multiple tasks in parallelCopy the code
10. When to use multiple processes in Android development? What are the benefits of using multiple processes?
To know when to use multi-process, you need to know the Android multi-process philosophy: in general, an application is a process. The process name is the application package name. Process is the basic unit of system allocation of resources and scheduling, so each process has its own independent resources and memory space, other processes are not free to access the memory and resources of other processes that how to let their own applications have multiple processes? When our four major components are registered in the AndroidManifest file, this property is Andriod: Process 1. Here you can specify the process in which the component is located. The default is the main application process. When you specify another process, the system will create the process (if it has not already been created) when the component is started, and then the component is created. You can override the onCreate method of the Application class to print out its process name so that it is clearly visible. When setting the Android: Process attribute, note that if android: Process =":deamon", a name starting with: indicates that this is a private process for the application, otherwise it is a global process. The process name of a private process is automatically preceded by a colon, while that of a global process is not. We usually have private processes and rarely use global processes. 2. The obvious benefit of using multiple processes is to share the memory burden of the main process. As our application gets bigger and bigger, it has more and more memory, so by putting some independent components in different processes, it doesn't occupy the memory space of the main process. There are other benefits, too. If you're interested, you'll notice that there are a lot of apps in the Android background process that are multi-process because they have to live in the background, especially for instant messaging or social applications, but multi-process is pretty much overused now. The typical usage is to start a lightweight private process that is invisible, send and receive messages in the background, or do something time-consuming, or boot the process, and then do listening, etc. There is also the daemon to prevent the main process from being killed. The daemon and the main process monitor each other and restart it if one of them is killed. On the downside, it takes up more space in the system. If everyone uses it in this way, the system memory will be easily filled up and lead to congestion. It consumes the user's power. The application architecture becomes more complex as it handles communication between multiple processes.Copy the code
11. What are the defects of multi-process and how to solve them
The first thing to make clear is that the memory space between processes is not visible. Therefore, after starting multi-process, we need to face the following problems: 1) Multiple reconstruction of Application. 2) Static member invalidation. 3) File sharing problems. 4) Breakpoint debugging problems. Solution: 1), You can use the process Id in the onCreate function of the Application to identify different processes and then do different things. 2) Use an Intent or aiDL to communicate with processes. This can result in competing access to resources, resulting in things like database corruption, data loss, and so on. In the case of multi-threading, we have locking mechanism to control the sharing of resources, but in the multi-process is more difficult, although there are file locking, queuing and other mechanisms, but it is difficult to achieve in Android. The solution is not to access the same file concurrently. For example, if the child process is involved in the operation of the database, you can consider calling the main process for the operation of the database. 4) Debugging is to track the stack information in the running process of the program. Since each process has its own independent memory space and stack, debugging between different processes cannot be realized. This can be done by removing the Android: Process tag from androidmanifest.xml during debugging. This ensures that the debugging state is in the same process and the stack information is consistent. After debugging, restore the label.Copy the code
12. What is ANR? How can ANR be avoided and resolved?
There are generally three types of ANR: 1: KeyDispatchTimeout(5 seconds) - Major types of key or touch events that do Not respond within a specified period of time 2: BroadcastTimeout(10 seconds) BroadcastReceiver cannot be processed within a specified period of time. 3: ServiceTimeout(20 seconds) - The BroadcastReceiver cannot be processed within a specified period of timeCopy the code
13. What are the common ideas for solving sliding conflicts on Android?
The related sliding component overrides onInterceptTouchEvent and then determines whether to intercept the current operation based on x and y valuesCopy the code
14. How to set an application as a system application?
To become a system application, first compile under the Android source SDK of the corresponding device. After compiling: The Android device is a Debug version and has already been root, directly push the APK to system/app or SY STEM /priv-app with ADB tools. If the device is not root, you need to compile and burn the device image again. Some permissions, such as WRITE_SECURE_SETTINGS, are not available to third-party applications and can only be compiled in the source code of the corresponding device and used as a system app.Copy the code
15. What’s a good way to detect memory leaks?
DataObject totalSize size, whether stable in a range, if the operation procedure, increasing, indicating a memory leak 2. BlankActivity Manually triggers GC for before-and-after comparison to see if the object is recovered and located in time: View the histogram entry, select an object, and view its GC reference chain. If there is a GC reference chain, it cannot be recycled. 2Copy the code
16. What is your understanding of Context in Android?
Context: A parameter that contains Context information (external values). Android has three types of Context: Application Context,Activity Context, and Service Context. It describes information about an application environment, through which we can obtain the application's resources and classes. It also includes application-level actions such as starting an Activity, sending a broadcast, receiving an Intent, and so onCopy the code
17. How do you achieve multi-resolution adaptation in the normal development process?
1. Create layout files with different resolutions. 2. Create resource pictures with different resolutions. At the start of the program, get the density and resolution of the current screen, in the code for adaptation 4. Write dimen files for different resolutions. 5. Use fragmentsCopy the code
18. Tell me about a time when you solved a BUG at work.
2. Breakpoint debugging 3. Output Log information one by one near the exception code, see the result prompt 4. Find problems, find ideas, if you encounter technical bottlenecks can check blogs, forums, Baidu, friends, colleagues and so onCopy the code
19. Why is the static keyword recommended when declaring ViewHolder(or Handler) inner classes?
A static inner class is not a static inner class. A non-static inner class implicitly holds a reference to an external class, so if you define an inner class as static, you can't call an instance method of an external class. In this case, a static inner class is a declaration that doesn't hold a reference to an external class. ViewHolder A static inner class, you can dereference a ViewHolder and an external class. ViewHolder is pretty simple, so it's okay if you don't call it static. That's true, but if you define it as static, you know what it means. If one day you add some complicated logic to the ViewHolder and do some time-consuming work, then if the ViewHolder is not a static inner class, you could easily leak memory. If it's static, you can't directly refer to external classes, forcing you to focus on how to avoid referencing each other. So it is a good practice to define the ViewHolder inner class as static 2. Non-static inner classes implicitly hold strong references to external classes, which can leak memory. Using a viewhod ler does not leak memory. Static is a good habit. For handlers, it is recommended to use static, then save the external class as a weak reference when you need to refer to the content of the external class, and then pull out the call.Copy the code
Such as:
static class MyHandler extends Handler {
private WeakReference<Context> mActivity;
public MyHandler(Context activity) {
this.mActivity = new WeakReference<Context>(activity);
}
public void handleMessage() {
//...
Context c = mActivity.get();
c.sendBroadcast(...);
}
}
Copy the code
20. How to display a super image or long image without losing authenticity?
1. Compress the image by calculating the inSamleSize value of the bitmapFactory. Options object. Use WebView to load image 3. Use MapView or TileView to display image (similar to map mechanism) 4. BitmapRegionDecoder partial loadCopy the code
21. How is the network layer designed in your application?
1. On the basis of HttpUrlConnection encapsulation of common methods,get, POST, upload, download, (breakpoint continuation) including request success, failure, request, processing success and network problems encapsulation, using interface callback or broadcast and UI interaction on the network request result cache, Separate processing, such as image caching with Lrucache and File. 2. Android-async-http encapsulates common methods such as GET, POST, upload and download; The specific usage is usually with the business logic, and mine is handled asynchronously. Direct use of xUtils, afinal okHttp, Volley and other open source third-party frameworksCopy the code
22. How to understand Bitmaps and how to optimize them?
Itmap is a class commonly used in Android that represents an image resource. Bitmap consumes a lot of memory. If you do not optimize the code, OOM problems often occur. There are usually several optimization methods: 1. Use cache 2. Compress images 3. Recycle in time: It depends on the situation when you need to manually call recycle, but the principle is that when you stop using Bitmao, you need to recycle it. In addition, we need to note that before 2.3, Bitmap objects and pixel data were stored separately in the Java Heap while pixel data was stored in Native Memory. In this case, it is necessary to call recycle Memory to recycle Memory But after 2.3,Bitmap objects and pixel data are stored in the Heap and can be reclaimed by GC.Copy the code
23. Optimizations for loading fragments in ViewPager? How to achieve delayed loading when switching interface like wechat?
Private Boolean hasLoadedOnce = false; @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); If (this.isvisible ()) {// check whether the fragment isVisible if (isVisibleToUser &&! HasLoadedOnce) {// code area}}}}Copy the code
24. What is an AAR? What’s the difference between an AAR and a JAR?
Aar, Maven project type should also be AAR, but the file itself is a zip file with the following items: / androidmanifest.xml (mandatory) /classes.jar (mandatory) /res/ (mandatory)/r.xt (mandatory) /assets/ (optional) /libs/*.jar (optional) /jni/*.so (optional) /proguard. TXT (optional) /lint.jar (optional) These entries are located directly at the root of the zip file where the r.file is the output of aapt with the -- output-text-symbols parameter. Jar packages cannot contain resource files, such as drawable files, XML resource files, etc. Aar can.Copy the code
25. How do I encrypt urls to prevent them from being hacked?
Https certificate bidirectional encryption authentication ensures securityCopy the code
26. What design patterns do you use in your daily development? Can you talk about the scenarios in which these design patterns are used?
The more common ones are the singleton pattern (used when only one object is instantiated in memory) and the adapter pattern (ListView list and GridView grid adapter) Builder mode (Alertdialog. Builder(dialog building)), observer mode is more subtle, in the Adnroid source code,BaseAdapter NotifyDataSetChanged implementationCopy the code
27. Tell me what you think about Android thread priorities
Generally speaking, Android threads can be divided into UI threads and background threads. If the thread is started from UI, its priority is Default and belongs to Default group, and it will compete with UI threads equally for CPU resources. Note this in particular: it is recommended to set the thread to background in cases of high UI performance requirements: Process. SetThreadPriority (Process. THREAD_PRIORITY_BACKGROUND) / / Android developers will require explicit worker threads to background group. new Thread(new Runnable() { @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); } }).start()Copy the code
28. What is the essence of OOM?
Dalvik VM mainly is the Java heap memory management, due to the limitation of mobile devices, a general applications use memory can't more than the default value of 32 m there are differences between the different devices, by the adb shell getprop | Grepdalvik. Vm. Heapgrowthlimit command to see when on DVM application heap memory is greater than the default memory value, then application will throw an OutOfmemoryErrorCopy the code
29. What is double buffering?
There are two ways to refresh a View in Android: invalidate(); The other is postInvalidate(), where the former is used in the UI thread itself and the latter is used in non-UI threads. Screen flicker is a common problem in graphics programming. Complex drawing operations can cause rendered images to flicker or have other unacceptable appearance. The use of double buffering solves these problems. Double buffering uses memory buffers to solve flicker problems caused by multiple draw operations. When double-buffering is used, all drawing is done in the memory buffer first, rather than directly on the screen. When all the drawing is done, copy the image from the memory buffer directly to the screen. Since only one graphics operation is performed on the screen, the image flicker problem caused by complex drawing operations is eliminated. To implement double buffering in Android, you can use a background canvas, backCanvas, to do all drawing operations on it first. After the drawing is finished, copy the backCanvas to the canvas associated with the screen as follows: Bitmap bitmap = new Bitmap() Canvas backcanvas = new Canvas(bitmap) backcanvas.draw()... Canvas c = lockCanvas(null); c.drawbitmap(bitmap); UnlockAndPost (c); unlockAndPost(c);Copy the code
30. A list has 10 items displayed on the screen, and each item is refreshed once in an average of 10ms. What problems may occur and how to solve them?
1. The screen may flicker due to frequent and rapid refresh requests. 2. Even after sliding, the ANR prompt box will pop up. Buffer data and reduce the refresh times. The resolution ability of human visual fluency is the worst at 12fps, and movies are generally at 24fps. Therefore, try to complete all CPU and GPU computation, drawing, rendering and other operations within 16ms each time; otherwise, frame loss and lag may occur. Therefore, we should design an in-memory data buffer to buffer the data to be refreshed, and then design the refresh controller to read the content at least every 16ms to uniformly refresh.Copy the code
31. Network hierarchy
- OIS stands for Open System Interconnect,
- The classification of the layers of the OSI seven-layer reference model follows the following principles:
1. All network nodes at the same layer have the same hierarchy and have the same functions. 2. Adjacent layers of a node communicate with each other through interfaces (logical interfaces). 3. Each layer in the seven-tier structure uses the services provided by the next layer and provides services to its upper layer. 4. Peer layers of different nodes communicate with each other based on protocols.Copy the code
- OSI seven layer model
Application layer file transfer E-mail file service virtual terminalCopy the code
To be continued…
Share with you
I want to work my way up
Fly forward on the blades at the highest point
Let the wind blow dry tears and sweat
I want to work my way up
Waiting for the sun to watch its face
Little days have big dreams
I have my day
Let the wind blow dry tears and sweat
One day I will have my day