Android Technology Summary

Source: Internet
Author: User
Tags asymmetric encryption

1. To make a ListView as smooth as possible, how do you usually optimize at work?
①item layout, the less hierarchy the better, use the Hierarchyview tool to view optimizations.
② Multiplexing Convertview
③ using Viewholder
When there is a picture in the ④item, asynchronously loads
⑤ the picture is not loaded when fast sliding
When you have pictures in ⑥item, you should compress the pictures appropriately.
⑦ Implementing paging of data

2. For Android security issues, you know how much
① Error Export Component
② parameter check is not strict
③webview introduces various security issues, JS injection in WebView
④ no confusion, no two-time packaging
⑤ storing key information in plaintext
⑦ Error using HTTPS
⑧ Cottage Encryption Method
⑨ abuse of permissions, memory leaks, using debug signatures

3. How do I reduce the APK package size?
Code
Keep good programming habits, don't repeat or use code, add Libs carefully, remove unused libs.
Using Proguard to confuse the code, it optimizes the unused code, and can reduce the size of the installation package after it is confused.
Native code section, in most cases only need to support Armabi and x86 architecture. If it is not necessary, you may consider taking away the x86 part.
Resources
Use the lint tool to find resources that are not used. Remove unused pictures, string,xml and so on. Resources under the Assets directory make sure that there are no files that are not used.
When you build the APK, the AAPT tool itself optimizes PNG, but you can use other tools such as tinypng to pre-compress the image further.
JPEG or PNG, choose as needed, at some point JPEG can reduce the volume of the picture. For the 9.png picture, can stretch the area as small as possible, in addition, you can use the 9.png stretch to achieve large-picture effect when try not to use the whole large map.
Strategy
Selectively provide hdpi,xhdpi,xxhdpi image resources. It is recommended to give priority to the xhdpi picture, for mdpi,ldpi and xxxhdpi to provide a different part of the needs.
Reuse existing picture resources as much as possible. For example, a symmetrical picture, you only need to provide one, another picture can be implemented by the way the code is rotated.
Can be used to draw the implementation of the function, try not to use a large number of pictures. For example, reduce the use of multiple images to make up the animate-list animationdrawable, this way provides a lot of pictures occupy space.

4.Android What is symmetric and asymmetric encryption in a way that interacts with the server?
Symmetric encryption, that is, the encryption and decryption of data are using the same key, the algorithm has DES.
Asymmetric encryption, encryption and decryption are using different keys. Before sending the data, the public and private keys are generated with the service-side contract, and the data encrypted with the public key can be decrypted with the private key instead. The algorithm in this area has RSA. Both SSH and SSL are typical asymmetric encryption.

5. What happens next when the device is switched to the screen?
1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice
2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
3, set the activity android:configchanges= "Orientation|keyboardhidden", the screen will not recall the various life cycle, will only execute onconfigurationchanged method

6.Android What are the two ways to start a service? What is the application of them?
If the background service can be run independently after the start, you can use StartService. Music player can be used this way. They will run until you call stopself or StopService. You can communicate with a running background service by sending intent or receiving intent, but most of the time you just start the service and let it run independently. If you need to communicate more frequently with a background service through a continuous connection, it is recommended to use BIND (). For example, you need location services to constantly pass the updated location to the UI. Binder is a bit more complex than intent, but you can only use it if you really need it.
StartService: The life cycle is different from the caller. Service will still run if the caller does not call StopService and exits immediately after startup
Bindservice: The lifecycle is bound to the caller, and once the caller exits, the service calls Unbind->ondestroy

7. Talk about your understanding of the context in Android?
Context: A parameter that contains contextual information (an external value). The context in Android is divided into three kinds, application context, Activity context, Service context.
It describes the information of an application environment through which we can get the resources and classes of the application, as well as some application-level actions, such as starting an activity, sending a broadcast, receiving intent information, etc.

Is the 8.Service OnCreate callback in the UI thread?
The various callbacks for the service life cycle, like other application components, are running in the main thread, affecting your UI operations or blocking other things in the main thread

9. Please describe the internal implementation of the next asynctask, what is the applicable scenario?
Asynctask internal is also the handler mechanism to do, but Android provides the execution framework to provide a thread pool to perform the corresponding task, because the size of the thread pool problem, so asynctask should only be used to perform time-consuming tasks, such as HTTP requests, Large-scale downloads and database changes do not apply to Asynctask because it causes the thread pool to clog and there are no threads to perform other tasks, resulting in a situation where asynctask cannot perform at all.

10. What is your understanding of the binder mechanism?
Binder is an IPC mechanism, a tool for inter-process communication.
The Java layer can use the Aidl tool to implement the appropriate interface.

What are the implementation methods for interprocess communication in 11.Android?
Intent,binder (aidl), Messenger,broadcastreceiver

12. Introduce the basic process of implementing a custom view
1. Custom View Properties Write Attr.xml file
2. Reference in layout file and reference namespace
3, in the construction method of the view to get our custom properties, in the custom control to read (construction method to get the Attr.xml file value)
4. Rewrite onmesure
5. Rewrite OnDraw

What is the transfer mechanism of touch events in 13.Android?
Related APIs for 1.Touch event delivery are dispatchtouchevent, Ontouchevent, onintercepttouchevent
2.Touch event-related classes have View, ViewGroup, Activity
The 3.Touch event is encapsulated as a Motionevent object that encapsulates gestures that are pressed, moved, loosened, and so on
4.Touch events are usually sent from activity#dispatchtouchevent, and as long as they are not consumed, they are passed down to the lowest view.
5. If every view that the touch event passes to does not consume events, then the touch event is passed backwards and is eventually referred to activity#ontouchevent for processing.
6.onInterceptTouchEvent is unique to viewgroup and can intercept events.
When the 7.Down event arrives, if a view does not consume the event, then the subsequent Move/up event will not give it

What are the implementations of 14.Android multi-threading?
Thread & Asynctask
Thread can be pooled with loop and Handler to establish a message processing queue
Asynctask can be used as a thread pool to process multiple tasks concurrently

When is a multi-process used in 15.Android development? What are the benefits of using multiple processes?
To know how to use multiple processes, first know the multi-process concept in Android. In general, an application is a process, and the name of the process is the application package name. We know that processes are the basic unit of system allocation of resources and schedules, so each process has its own separate resources and memory space, and other processes cannot arbitrarily access the memory and resources of other processes.
So how do you get your app to have multiple processes?
Very simply, when our four components are registered in the Androidmanifest file, there is a property of android:process,1. Here you can specify the process in which the component is located. The default is the app's main process. When the system starts this component, it is created (if it has not yet been created), and then the component is created before it is specified as another process. You can overload the OnCreate method of the application class, print out its process name, and you can see clearly. When setting the Android:process property, there is a place to note: If it is android:process= ":d Eamon" to: the first name, it means that this is an application private process, otherwise it is a global process. The process name of the private process is automatically prefixed with the package name before the colon, while the global process does not. Generally we have private processes and seldom use global processes. Their specific differences do not know who can add.

2. The obvious benefit of using multiple processes is to share the memory pressure of the main process. As our application grows larger and more memory is used, the separate components are put into different processes, and it does not occupy the memory space of the main process. Of course there are other benefits, the people will find many applications in the Android background process is a number of processes, because they have to reside in the background, especially instant messaging or social applications, but now many processes have been used to rot. The typical usage is to start an invisible lightweight private process, send and receive messages in the background, or do some time-consuming things, or start the process on boot, and then do the listening. There is also to prevent the main process from being killed Daemon, the daemon and the main process to monitor each other, a party was killed to restart it. There should be other benefits, and there's not much to say here.

3. The bad words, more occupy the system space, everyone so use the system memory is easy to fill up and lead to Kaka. Consumes the user's power. The application architecture can become complex and should be the communication between multiple processes to be handled. Here's another question.

What is 16.ANR? How to avoid and solve the ANR?
Anr:application not responding, i.e. application unresponsive
There are generally three types of ANR:
1:keydispatchtimeout (5 Seconds) – main type
Key or touch events do not respond at a specific time

2:broadcasttimeout (seconds)
Broadcastreceiver cannot process completion at a specific time

3:servicetimeout (seconds) – small probability type
Service cannot process completion at a specific time

There are two common reasons for timeouts:
(1) The current event does not have a chance to be processed (UI line is impersonating is not completed in time before processing or looper is blocked for some reason)
(2) The current event is being processed, but not completed in time

The UI thread tries to do only the UI-related work, the time-consuming work (database operations, I/O, the connection network, or other actions that might hinder the UI thread) from being processed into separate threads, using handler to handle the interaction between the UI thread and thread.

The UI thread mainly includes the following:
Activity:oncreate (), Onresume (), OnDestroy (), OnKeyDown (), OnClick ()
Asynctask:onpreexecute (), Onprogressupdate (), OnPostExecute (), OnCancel ()
Mainthread handler:handlemessage (), post (runnable R)
Other

What are the common ideas for solving sliding conflicts at 17.Android?
The associated slide component overrides the Onintercepttouchevent and then determines whether or not to intercept the current operation according to the XY value

18. How to set up an application as a system application?
To become a system application, first of all in the corresponding device of the Android source code SDK compiled, after compiling:
This Android device is a Debug version and is already rooted, push this apk with the ADB tool directly to System/app or System/priv-app.
If a non-root device, you need to re-burn the device image after compiling.

Some permissions (such as Write_secure_settings), are not open to third-party applications, can only be compiled in the corresponding device source code and then used as a system app.

19. Android Memory Leak Research
Android memory leaks refer to some objects in the process (garbage objects) that have no use value, but they can be referenced directly or indirectly to GC roots resulting in the inability to be recycled by GC. Useless objects occupy memory space, so that the actual memory can be used to become smaller, the image is the memory leak.
Scene
The static variables of the class hold big Data Objects
Static variables maintain references to large data objects for a long time, preventing garbage collection.
Static instances of non-static inner classes
A non-static inner class maintains a reference to an instance of an external class, and if an instance of a non-static inner class is static, the reference to the external class is maintained indirectly for a long time, preventing it from being recycled.
Resource object not closed
Resource objects such as cursor, File, and Socket should be closed immediately after use. Failure to close in finally results in an exception where the resource object is not released.
Registration object is not anti-registered
Non-registration causes the observer list to maintain a reference to the object, preventing garbage collection.
Handler temporary memory leaks
Handler interacts with the main thread by sending a message, and the message is stored in MessageQueue after it is sent, and some messages are not processed immediately. There is a target in the message, which is a reference to handler, and the longer the message exists in the queue, the handler cannot be reclaimed. If the handler is non-static, it can cause activity or service not to be recycled.
Since Asynctask is also a handler mechanism, there is also a risk of memory leaks.
This kind of memory leaks, is generally temporary.

20. What is the best way to detect memory leaks?
Detection:
1. DDMS Heap discovers memory leaks
DataObject totalsize size, whether stable in a range, if the operating procedures, increasing, indicating memory leaks
2. Use heap tool to compare memory snapshots before and after
Blankactivity manually triggering GC before and after comparison, whether the object is recycled in time

Positioning:
1, Mat plug-in opens. Hprof Specific location memory leaks:
To view the histogram item, select an object to view its GC reference chain, because there is a GC reference chain that indicates that it cannot be recycled
2, Androidstudio's allocation Tracker:
Observe the memory allocations during the period, which objects are created and when created, thus accurately locating

Android Technology Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.