In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this article, the editor introduces in detail "what are the basic interview questions for Android", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what are the basic interview questions for Android" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.
A performance optimization 1. How to analyze the performance of Android applications
The main performance of android is response speed and UI refresh speed.
You can refer to the blog: introduction to Android system performance tuning tool
First of all, in terms of the time consuming of the function, there is a tool called TraceView, which comes with androidsdk and is used to measure the time consuming of the function.
UI layout analysis, there can be 2 pieces, one is Hierarchy Viewer can see the View layout level, and each View refresh loading time.
This allows you to quickly locate which layout & View takes the longest time.
There is also a custom View to reduce the level of view.
two。 Under what circumstances can lead to memory leaks
Memory leaks are a troublesome problem.
When will a memory leak occur? Root cause of memory leak: objects with long lifecycles hold objects with short lifecycles. Short-period objects cannot be released in time.
i. Memory leak caused by static collection class
Mainly hashmap,Vector, etc., if these collections are not setnull in time, they will hold these objects all the time.
The II.remove method cannot delete the set set Objects.hash (firstName, lastName)
After testing and modification of hashcode, there is no way to remove.
III. Observer when we use listeners, it is often addxxxlistener, but when we do not need it, it is easy to forget removexxxlistener, it is easy to memory leak.
The broadcast has no unregisterrecevier.
iv. Various data links are not closed, database contentprovider,io,sokect, etc. Cursor
v. Inner class:
The inner class in java (anonymous inner class) holds the strong reference this of the host class.
So if it is the operation of the background thread like new Thread, when the thread does not end the execution, the activity will not be recycled.
References to Context, when TextView, etc., all hold references to the context. If there is a static drawable, it will prevent the memory from being freed.
vi. Single case
A singleton is a global static object. When holding a replicated class A, A cannot be freed, memory leak.
3. How to avoid OOM exceptions what is the first OOM?
When the program needs to apply for a "big" memory, but the virtual machine cannot give it in time, even after the GC operation
This will throw OutOfMemoryException, that is, OOM.
What about Android's OOM?
To reduce the impact of a single APP on the entire system, android sets a memory limit for each app.
Public void getMemoryLimited (Activity context) {ActivityManager activityManager = (ActivityManager) context.getSystemService (Context.ACTIVITY_SERVICE); System.out.println (activityManager.getMemoryClass ()); System.out.println (activityManager.getLargeMemoryClass ()); System.out.println (Runtime.getRuntime (). MaxMemory () / (1024 / 1024));}
Measured by HTC M7, the upper limit of 192 M. In general, 192 M is the upper limit of 512m, but android allows the use of a larger RAM due to some special cases.
How to avoid OOM to reduce the occupation of memory objects
I.ArrayMap/SparseArray replaces hashmap
ii. Avoid using Enum in android
iii. Reduce the memory footprint of bitmap
InSampleSize: zoom ratio. Before loading the image into memory, we need to calculate an appropriate zoom ratio to avoid unnecessary loading of large images.
Decode format: decoding format, choose ARGB_8888/RBG_565/ARGB_4444/ALPHA_8, there is a big difference.
iv. Reduce the size of resource images. If the image is too large, you can consider loading it in segments.
Reuse of memory objects
Most of the reuse of objects uses the technology of object pooling.
Reuse of I.listview/gridview/recycleview contentview
The reuse ARGB_8888/RBG_565/ARGB_4444/ALPHA_8 of the II.inBitmap property for memory objects
This method is useful under certain conditions, such as when loading thousands of images.
iii. Avoid new objects in ondraw methods
IV.StringBuilder instead of +
How to catch uncaught exceptions in 4.Android
CrashHandler
The key is to implement Thread.UncaughtExceptionHandler.
Then register in the oncreate of application.
What is 5.ANR? How to avoid and solve ANR (important)
ANR- > Application Not Responding
That is, within the specified time, there is no response.
There are three types:
1)。 KeyDispatchTimeout (5 seconds)-the main type of keystroke or touch event does not respond at a specific time
2)。 BroadcastTimeout (10 seconds)-BroadcastReceiver cannot be processed within a specific time
3)。 ServiceTimeout (20 seconds)-small probability type Service cannot be processed within a specific period of time
Why it times out: there is no opportunity to handle events & event processing timed out
How to avoid ANR
The key to ANR
Is handling timeouts, so you should avoid handling complex logic and calculations in UI threads, BroadcastReceiver, and service main threads
And leave it to work thread to operate.
1) avoid time-consuming operations in activity, oncreate & onresume
2) avoid doing too much in onReceiver
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) try to use handler to handle the interaction between UI thread and workthread.
How to solve ANR
First, locate the log that occurs in ANR:
04-01 13 2b263310com.android.email/com.android.email.activity.SplitScreenActivitypaused=false 12 I/InputDispatcher 11.572: Application is not responding:Window {2b263310com.android.email/com.android.email.activity.SplitScreenActivitypaused=false}. 5009.8ms since event, 5009.5ms since waitstartedCPUusage from 4361ms to 699ms ago-CPU usage before ANR 04-0113 ANR 1215 E/ActivityManager 15.872 E/ActivityManager (220): 100%TOTAL: 4.8% user + 7.6% kernel + 87% iowait04-0113 CPU usage after CPUusage from 3697ms to 4223ms later:-- ANR
As you can see from log, cpu is doing a lot of io operations.
So you can see where the io operates.
Of course, it is also possible that the cpu footprint is not high, that is, the main thread is occupied by block.
What are the ways of communication between 6.Android threads
1) shared variables (memory)
2) Pipeline
3) handle mechanism
RunOnUiThread (Runnable)
View.post (Runnable)
The difference between 7.Devik process, linux process and thread
Dalvik process.
Each android app occupies an independent dvm virtual machine and runs in the linux system.
So dalvik process and linux process can be understood as a concept.
8. Describe the system architecture of android
From childhood to the top is:
Linux kernel,lib dalvik vm, application framework, app
How is memory limited by 9.android applications? How should we use memory properly?
Activitymanager.getMemoryClass () gets the memory limit.
With regard to the rational use of memory, it is actually to avoid OOM & memory leaks are described.
10. Briefly describe what is the structure of android application
1) main code
Unit test
3) mianifest
4) res- > drawable,drawable-xxhdpi,layout,value,mipmap
Mipmap is a technology that has existed for a long time, which translates into texture mapping technology.
Google recommends that only startup images be put in.
5) lib
6) color
11. Please explain the difference between Android program runtime permissions and file system permissions
System permissions for files are specified by the linux system, read-only, read-write, etc.
Runtime permissions are access to app on a system, allow, deny, and ask. This feature prevents illegal programs from accessing sensitive information.
How and how 12.Framework works, how Activity generates a view, and what is the mechanism
Framework is the encapsulation of linux kernel,lib library by android system, and provides WMS,AMS,bind mechanism, handler-message mechanism and other ways for app to use.
To put it simply, framework is the environment in which app lives.
1) when Activity is in the attch method, it creates a phonewindow (a subclass of window)
2) the setContentView method in onCreate, which creates a DecorView
3) the addview method of DecorView, which loads the layout in layout.
13. What's the difference between multi-thread communication and multi-process communication, and how to implement them respectively?
For communication between threads, refer to point 6.
Inter-process communication: bind mechanism (IPC- > AIDL), linux level shared memory, boradcast
Communication between Activity, activity & serview, whether they are in the same process or not.
14.Android screen adaptation
Screen adaptation: xxxdpi, wrap_content,match_parent. Get the screen size and do the processing.
Dp to fit the screen, sp to determine the font size
Drawable-xxdpi, values-1280*1920 and so on are the adaptation of resources.
Wrap_content,match_parent, these are view adaptations.
Weight, this is the fit of weight.
15. What is AIDL and how to use it
Android Interface Definition Language
AIDL uses the bind mechanism to work.
Parameters:
Java native parameters
String
Parcelable
The list & map element needs to support AIDL
16.Handler mechanism
Reference: android process / thread management (1)-- the framework of the message mechanism.
17. Event distribution mechanism
Android event distribution mechanism
18. The subthread sends a message to the main thread to update UI. What else is there besides handler and AsyncTask?
EventBus, broadcast, view.post, runinUiThread
But regardless of all kinds of tricks, there are essentially two: handler mechanism + broadcasting.
19. Is it possible to new handler in child threads? Why
It has to be possible. A child thread can new a mainHandler and then send a message to UI Thread.
What are the types of animation in 20.Android, and what are their characteristics and differences?
View animation, or motion tween. Just a visual effect, the actual view properties do not change, the performance is good, but there are few ways to support.
Attribute animation, by changing the attributes to achieve the effect of animation, slightly poor performance, support for clicks and other events. Android 3.0
Frame animation, drawn frame by frame through drawable.
Gif animation, the principle is the same as above, drawn by canvas.
21. How to modify Activity entry and exit animation
OverridePendingTransition
The difference between 22.SurfaceView and View
Updates to view must be done in UI thread
Surfaceview will have a separate thread to update the ui.
Surfaceview supports open GL drawing.
Second, the use of the project framework 23. What frameworks and platforms have been used in development?
I.EventBus event distribution mechanism, implemented by handler, communication between threads
II.xUtils- > DbUtils,ViewUtils,HttpUtils,BitmapUtils
iii. Baidu Map
IV.volley
V.fastjson
VI.picciso
vii. Friendly alliance
VIII.zxing
IX.Gson
24. Used those custom View
Pull2RefreshListView
25. Custom controls: public class CycleView extends View {Paint mPaint = new Paint (); public CycleView (Context context) {this (context, null);} public CycleView (Context context, AttributeSet attrs) {super (context, attrs); initView ();} private void initView () {mPaint.setAntiAlias (true); mPaint.setStyle (Paint.Style.STROKE); mPaint.setStrokeWidth (20) } @ Override protected void onDraw (Canvas canvas) {super.onDraw (canvas); canvas.drawCircle;}} read here, this article "what are the basic Android interview questions" has been introduced, and you need to practice and use the knowledge points of this article before you can understand it. If you want to know more about related articles, welcome to follow 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.