How does the headline screen fit today?
1: first calculate the density. Calculation formula: the total screen width of the current device (in pixels) / the total width of the design drawing (in DP) = the reason why 1 DP accounts for the number of pixels of the current device to calculate the density: what bits are filled in the layout file will be converted into PX finally. The system uses the above method to transfer you to the project Units filled in anywhere in are converted to PX
However, only one of the height or width can be used as the benchmark in the default project of today’s headline adaptation scheme
A brief introduction to the reinforcement and use platform in Android?
- Reinforcement: prevent code decompilation and improve code security
- Strengthen the three-way platform, bang bang security, 360 reinforcement, love encryption, etc
Difference: the security of bang bang, 360 reinforcement can’t see the class in the project, love encryption can see the Java class, can’t see the method implementation body in the project, the effect is a little worse than the previous one
The underlying principle of reinforcement: the third-party reinforcement application will generate an APK, and then read out your APK, which is encapsulated in the APK of the third-party application
How to slim down for APK?
1) use confusion,
2) turn on shrinkresource (shrink shrink), and the unused image will be turned into a pixel point
3) delete useless language resources (delete international files)
4) for large non transparent images, JPG (no transparency information) is used instead of PNG format
5) image compression with tinypng
6) use webp image format to further compress image resources
7) when using the third-party package, add the code to the project to avoid referencing the whole third-party library
Describe the principle and common operation of multi-channel packaging?
Generate an APK file with channel ID for each channel (application market)
Principle: the user downloads and starts the application, obtains the channel identification and the unique identification of the device, and uploads it to the server. The server will determine whether it exists in the table of the server according to the obtained record and the channel number
1) friendly alliance multi-channel packaging: define a placeholder in the manifest file, and replace the placeholder in the gradle script (Python will be used)
2) meituan pack, create an empty file in meta data, identify the channel with the file name, and do a decompression and compression operation, which will be faster
3) for the new generation of multi-channel packaging, adding the channel ID to the end of the. APK file will not damage the source file
What are the data storage methods under Android?
1) internal storage, directly stored in internal files
2) for external storage, first determine whether external storage conditions are available, and then store
3) SP storage, the bottom layer is implemented by XML, and the internal data is stored in the form of key value pairs, which is suitable for lightweight storage. The types of data stored are Boolean, string, int
4) database storage, SQLite storage, lightweight database, powerful add, delete, change and query functions
5) content provider, which provides part of the data that it is willing to expose for external use
6) networked storage, etc
Sharepreference thread security issues?
The official document made it clear that SharedPreferences does not support multithreading and that the process is unsafe
If you want to achieve thread safety, you need to re implement its interface, as follows
Assuming that multiple processes access sharepreferences, how to ensure process security and data sharing?
The solution is to put forward the fields that need to share data and store them in a file.
How to effectively adapt the screen under Android development?
1: model adaptation, go to some statistical websites such as Youmeng, now call Youmeng + go to see the most popular Android model in the market, with targeted screenshot
2: screen adaptation, adapt to the mainstream xhdpi screen size, use layout such as relativelayout and linelayout, use matchparent, wrapcontent, and cooperate with weight and weight processing,
3: in the code, dp2px is used to convert the design to specific size,
4: the image uses stretchable. 9 image and ImageView uses scaletype to zoom;
5: use weight, equal scale, percentage layout, etc
1) permanently save the object and save the byte sequence of the object to the local file;
2) passing objects in the network by serializing objects;
3) passing objects between processes by serialization.
There are two options to implement serialization in Android: one is to implement the serializable interface (supported by Java se itself), and the other is to implement the Parcelable interface (a unique Android function, which is more efficient than the implementation of the serializable interface, which can be used for intent data transmission, or for interprocess communication (IPC)). It’s very simple to implement the serializable interface, just declare it, but it’s a little more complicated to implement the Parcelable interface, but it’s more efficient. This method is recommended to improve performance. The two implementation methods are still URL posting, which is convenient for you to query quickly
Two kinds of serialization correlation
Since Google recommends the serialization of Parcelable, here, we recommend one click serialization plug-ins,
Search for plug-ins in Android studio, as shown in the figure below. Write serialization (you don’t need to write at all). That’s a beauty~
Okhttp supports synchronous and asynchronous data requests, but asynchronous requests are made in sub threads (because the callback method is used in sub threads when native okhttp is used. To refresh the interface, you need to use handler, which can use third-party okhttp utils, okgo, etc.);
Okhttp includes thread pool, data conversion, gzip compression (to reduce traffic transmission), HTTP protocol cache, etc,
Advantages of okhttp – gzip compression is used to reduce the amount of data transferred and cache (reduce repeated requests);
Failed retry (if your service has multiple IP addresses, okhttp will use the alternate address if the first connection fails)
Okhttp is the encapsulation of HTTP protocol, which is relatively low-level, so it has strong expansibility and is easy to encapsulate;
Okhttp is more efficient based on NiO (JDK1.5, non blocking IO)
A fast and efficient injection framework, saving development time and reducing code volume (relying on plug-ins to dynamically generate views, click events, etc.)
1. Powerful view binding and click event processing functions, simplify code and improve development efficiency
2. Convenient handling of viewholder binding in adapter
3. It will not affect the efficiency of APP during operation and is easy to use and configure
4. Clear code and strong readability
1. Activity butterknife. Bind (this); must be after setcontentview(); and after the parent class bind, the child class does not need to bind again
2.Fragment ButterKnife.bind(this, mRootView);
3. The attribute layout cannot be modified with private or static, otherwise an error will be reported. (note permission)
4. Setcontentview() cannot be implemented by annotation. (some other annotation frameworks can)
Principle: use annotation and reflection to get binding viewid,
For details of the principle, please refer to this article of the author: Android customized butterknife framework. This paper introduces butterknife framework in detail and imitates a framework of annotation binding view
Rxjava concept, common operators and extensions?
An elegant asynchronous framework, replacing the previous asynctask / handler / xxx /
Its powerful operators, chain writing, thread switching, etc. help to improve development efficiency and quickly locate bugs
It has unexpected effect when used with retrofit,
Underlying principle: observer mode
Wait for some corresponding blogs
1: too many operators will increase learning cost time
2: it is easy to cause memory leak due to poor use (solution: rxlifecycle combined with rxjava is recommended to avoid the risk of memory leak)
The full name of anr is application not responding, i.e. “application not responding”. When the system cannot process the operation for a period of time, the system level will pop up the anr dialog box as shown in the figure above
In Android, the responsiveness of app is monitored by activity manager and window manager system services. Generally, anr dialog box will pop up under the following two conditions:
A) unable to respond to user input events (such as keyboard input, touch screen, etc.) within 5S
B) the broadcastreceiver cannot end within 10s
The primary reason for the above two situations is that there are too many blocking and time-consuming operations in the main thread (UI thread), such as file reading and writing, database reading and writing, network query, etc
How to analyze anr?
When anr is generated, the system will generate a traces.txt file and put it under / data / anr /. Developers can export it to the local ($ADB pull data / anr / traces. TXT.) through analysis, we can view the causes of anr according to specific logs (such as common blocking, CPU full load, memory leak)
Which scenes in Android are executed in the main thread?
1) activity life cycle callbacks are executed in the main thread
2) service is executed in the main thread by default
3) the onReceive callback of broadcastreceiver is executed in the main thread
4) the handlemessage of the handler of the looper without using the sub thread, and the post (runnable) is executed in the main thread
5) except doinbackground, the callback of asynctask is executed in the main thread
6) view’s post (runnable) is executed in the main thread, etc
Three level cache:
When we first open an application to obtain pictures or other resources, we first download them to the network, and then store them in memory cache and disk cache successively,
When we need to use the picture we just downloaded again, we don’t need to download it to the network repeatedly. We can find it directly from the memory cache and disk cache. Because the memory cache speed is fast, we prefer to find the picture in the memory cache. If we find it, we can use it,
If it is not found (memory cache size is limited), then we will go to disk cache again.
As long as we reasonably coordinate the use of these three layers of cache, we can improve the application performance and give users a better experience
Three level cache refers to memory cache, local cache and network cache. Their respective characteristics are fast memory cache speed, priority read, local cache speed second, memory does not have the resource information to read local memory, network cache speed is slow (the comparison object is memory cache and local cache), assuming that there is no local memory, just request network access.
When an instance is no longer needed in an application, but the object is still referenced, this situation is called memory leak. Android virtual machine allocates a certain amount of memory space for each application. When memory leaks to a certain extent, it will cause memory overflow.
Common causes of memory leaks:
1) static variables directly or indirectly refer to activity objects, which will cause memory leakage
2) static view is used for activity (view will hold the reference of activity’s object)
3) activity defines the static view variable???
4) imagespan references activity context
5) the context of activity is referenced in a single example (the context of application is required)
6) when using resources such as bradcastreceiver, contentobserver, file, cursor, stream, bitmap, etc., you should close or log off in time when the activity is destroyed, otherwise these resources will not be recycled, resulting in memory leakage.
7) objects saved by static collection are not eliminated in time (set to null when not in use)
8) in Java, non static (anonymous) internal classes will reference external class objects, while static internal classes will not reference external class objects
9) in activity, static member variables of non static internal classes (internal classes directly or indirectly refer to activity) are created
10) the thread includes the use of asynctask. After the activity exits, the thread is still running (the thread is in the dead cycle), and the activity or view object is used in the thread (solution: do not write the dead cycle directly, you can set a Boolean tag. When the activity is launched, set the tag to false)
11) for the use of handler object, the handler still has messages to process after the activity exits (solution: remove the messages after the activity exits)
12) memory leak caused by WebView (destroyed in ondestory)
How to analyze memory leak?
A: analyze through the Android studio window to check the memory allocation. If the operating application is that the memory keeps going up, it indicates that there is a memory leak
B: a tool for locating memory leak analysis — mat (memory analyzer tool)
C: use the open source library leakcanary to quickly locate memory leaks
Are the four components of Android related?
Activity is an application component that provides a screen (narrow sense is the interface of the current APP). Users can use it to interact to complete a task. (click, log in, jump to page)
All operations in an activity are closely related to the user. It is a component responsible for interaction with the user. You can use setcontentview (view) to display the specified control (set layout file).
In an Android application, an activity is usually a separate screen, on which you can display some controls or listen to and handle user events to respond.
Four startup modes of activity?
The start mode of activity refers to that the corresponding start mode can be set for the activity according to the actual development requirements, so as to avoid creating a large number of duplicate activities and other problems.
Standard is the default startup mode of activity, which can be configured without writing. In this mode, a new instance will be created by default. Therefore, in this mode, you can have multiple identical instances and also allow multiple identical activities to overlap. (clicking the back key will exit in sequence according to the stack order)
In singletop mode, an activity can have multiple instances, but multiple identical activities are not allowed to overlap. That is, if an activity starts the same activity at the top of the stack, it will not create a new instance, but will call its onnewintent method.
A single task indicates that there is only one instance. When he is started in the same application, if the activity does not exist, a new instance will be created in the current task. If it exists, the other activity destory above the task will be dropped and its onnewintent method will be called. If you start it in another application, a new task will be created and the activity will be started in the task. A single task allows other activities to coexist with it in a task. That is to say, if I open a new activity in the instance of the single task, the new activity will still be in the task of the instance of the single task.
There is only one instance, and this instance runs in a task independently. This task has only this instance, and no other activity is allowed.
Bradcastreceiver: (to be added)
The observer pattern in design pattern is used: message based publish / subscribe event model.
There are two ways to register: static registration and dynamic registration
ContentProvider: (to be added)
The external world can access the data in the content provider through the contentresolver interface. Uri Universal Resource Identifier URI represents the data to be operated, and every resource available in Android – image, video clip, etc. can be represented by URI. Content provider shares data by defining an open and unified interface. However, instead of calling these methods directly, the application uses a contentresolver object to call its methods instead. Contentresolver can talk with any content provider and cooperate with it to manage all related interactive communication. When the external application needs to add, delete, modify and query the data in the ContentProvider, the contentresolver class can be used to complete the operation. To get the contentresolver object, the getcontentresolver () method provided by context can be used.
Intentservice is a subclass of service, which has additional functions than ordinary service. Intentservice will create an independent worker thread to process all the intent requests; it will create an independent worker thread to process the code implemented by onhandleintent() method without multithreading; after all the requests are processed, intentservice will automatically stop, and developers do not need to manually call stopself() method to stop the service;
Briefly describe the differences between system. Exit (0), ondestore(), and activity. Finish()
1) system.exit (0) is the normal ending of the program. Kill the current process, aiming at the whole application
2) ondestore() method is the last step of the activity life cycle, and resource space is recycled. When reentering this activity, you must recreate it and execute the oncreate () method
3) activity. Finish() when you call this method, the system just moves the top activity out of the stack, and does not call ondestore() in time, that is, the occupied resources are not released in time.
Image optimization, and the use of image loading framework, such as Picasso, fresco, glide, etc?
1) use small pictures as much as possible to compress the pictures, bitmapfactory.options picture configuration class, inimplesize to zoom, and set the encoding mode of the pictures; use soft reference for the pictures, and release the picture memory when the memory is not enough; reuse the pictures, and use the three-level cache;
Instantly reclaim the unused bitmap objects;
2) Picasso does not support GIF. It caches the original picture of argb8888, which takes up a large amount of memory. The picture frame uses okhttp caching mechanism, uses HTTP protocol caching, and also loads asynchronously
3) fresco, the framework is introduced by Facebook, which is suitable for loading pictures in batches. The bottom layer is through three-level cache (Level 2 memory, level 1 disk)
Automatically replace with target image after loading successfully
4) glide, introduced by Google in 14 years, can load GIF chart, or according to the specified picture clarity. The underlying principle: maintain an object pool for bitmap. The object pool aims to improve performance by reducing object allocation. The object pool can also help improve rolling performance. API is simple and easy to call
Handler workflow basically includes four parts: handler, looper, message and messagequeue. But we often only use handler and message in our daily development. Message is responsible for carrying messages, in which a target is used to mark messages, obj is used to store content, and handler is responsible for the distribution and processing of messages.
How to use handler in development?
It’s not allowed to update the UI in the sub thread officially, so we often send the message that needs to update the UI directly to the handler, and rewrite the handler’s handlemessage() method to perform UI related operations.
Is there nothing to pay attention to when using handle?
Yes, if Handler is set as a private variable, Android Studio will report a warning, which may cause memory leaks. This situation can be avoided by setting up static internal class + weak reference or calling Handler.removeCallbacksAndMessages (null) in onDestroy () method.
The overall workflow of handler is divided into the following four steps:
Asynchronous communication preparation = > message queuing = > message loop = > message processing
A: asynchronous communication preparation
I: if the handler is created in the main thread, the handler object looper, message queue object messagequeue and handler object will be created directly in the main thread.
Note that looper and messagequeue belong to their creation thread.
II: looper objects are usually created by two methods: looper. Preparemainlooper() and looper. Prepare(). When creating looper objects, messagequeue will be created automatically.
III: after the messagequeue is created, looper will automatically enter the message loop. At this time, the handler automatically binds the looper and messagequeue of the main thread.
B: News enters the team
The worker thread sends the message message to the message queue through the handler, and the message content is generally UI operation. Sending messages is usually done by two methods: handler.sendmessage (message MSG) and handler.post (runnabe R). The team entry is usually handled through messagequeue.enqueueemessage (message MSG, long when).
C: message loop
It is mainly divided into two steps: “message queuing” and “message distribution”. Looper will retrieve the message in the message queue through a loop and distribute it to the handler who created the message. If the message queue messagequeue is empty during the message loop, the thread is blocked.
D: message processing
Handler receives the message from looper and starts processing.
Introduce yourself first?
Analysis: in addition to making a brief introduction to the interviewer, you also need to show the interviewer some of the characteristics that you must have for the job,
For example, the interview programmer profession needs to indirectly show the interviewer his / her rigorous thinking, handling of details, rational thinking, hypothesis demonstration, etc.; the interview product profession needs to indirectly show the interviewer his / her views on the product and unique thinking personality through some of his / her stories, etc
Entry point: whether their own characteristics meet the expected needs of the position
What are your hobbies?
In the eyes of enterprises and interviewers, if there is a positive correlation between the hobbies of job seekers and the positions they are applying for, they will be interested. The interviewer will also judge whether the values of the candidates fit in with the corporate culture and fit in well with the work team through their interests and hobbies. The candidate’s answer will likely add points to the interview.
Some of the personalities and career orientations reflected in the following interests and hobbies are available for reference:
1. Basketball, football, volleyball: team spirit, suitable for most positions.
2. Go, chess: strategic awareness, suitable for market or high-end positions.
3. Reading, classical music: elegant, suitable for civil service.
4. Tourism: the ability to adapt to different environments, the ability to learn quickly, suitable for sales business positions.
5. Dance: outgoing, easy to communicate, suitable for public relations and marketing positions.
What are your expectations and plans?
Analysis: on the surface, career development planning is to examine the long-term fit between you (job seeker), position and company, but in fact, such a big problem can not be expressed clearly between three eyes and two languages. The interviewer (whether HR or professional department) is mainly to see if you have a clear idea when answering questions, what is the working attitude shown in the answers, and if you have enough understanding of the company and the position. So no matter what the answer is, the key is not to be confused.
Entry point: still own characteristics, clear expression of future expectations and planning, and quick thinking
Talk about your strengths and weaknesses?
First of all, disadvantages:
The technical industry interview is basically conducted by the future colleagues and superiors of the post. This kind of interview is highly technical, and the behavior problem mainly focuses on whether you really want to do the job (rather than being a springboard or hearing about a decent salary) and whether your personality and culture are in line. All the answers should be organized around these two points (i.e. each experience should return to what you learned from the experience, the key skills required for the position, why the experience made you want to do the job, and what kind of personal style the experience reflects). It’s hard to make a good impression on this question because of a good answer,
The key is to avoid making a bad impression.
The main points are as follows:
1) avoid avoiding the important and ignoring the important, and don’t talk about a defect that can’t be considered as a disadvantage. For example, staying up late will make you sleepy, or (being polite) and so on.
2) avoid talking about non professional shortcomings, such as emotional cleanliness, pickiness of food, not good at shopping with his girlfriend, often do not know how to cook.
3) avoid talking about the weakness that can’t be improved. For example, I have to use a calculator to calculate, and I can’t use a book to understand.
4) avoid talking about fatal weaknesses, such as strange temper, dislike cooperation, being late and leaving early, etc.
What’s the best thing to talk about? I think there are three main points:
1) talk about the shortcomings that are already being corrected / have clear plans to correct them. In particular, you can fully demonstrate the shortcomings that can be solved in the near future.
2) talk about a defect corrected by using your advantages and bring out an advantage by the way. (this is a more efficient communication skill)
Relatively good answer:
1) the project / operation fails to be completed on schedule due to the pursuit of details. Through time management ability to change the way of work, first complete the framework and then improve the details to be solved;
2) I don’t know how to refuse. My colleagues ask for help and take care of it, which will affect my work progress. Set priorities through multi task processing ability, use the priority list to show the colleagues who ask for help their hands on work, and give them an estimate of when they can help, let them decide whether to ask for help or not, and solve the problem
3) in terms of solutions to the same problem, due to the different technical preferences and technical composition of the team members, it is easy to cause communication obstacles and affect the project plan, so we should learn efficient and effective communication methods and work skills
Android economics in the cold winter of capital
Android custom view – what is page?
It’s so easy to implement recyclerview levitation bar!
Apk’s past and present: from Android source to APK’s compilation and packaging process
If you are interested in technology development, you can pay attention to the public address: terminal R & D department, id:codeGoogler