当前位置:网站首页>Summary of Android interview questions of Dachang in 2022 (I) (including answers)

Summary of Android interview questions of Dachang in 2022 (I) (including answers)

2022-07-06 17:41:00 Code is not difficult to write

Preface

Now ,Android The employment situation of development posts is becoming increasingly severe , Want to stand out from many interviewers , Take the big factory offer, We must sort out the knowledge points comprehensively , Expand the question bank , And for the key knowledge that may be encountered in the interview , Conduct in-depth analysis .

This article is dedicated to Android Engineer prepared high salary interview real questions summary question bank , It covers many years of large factories and has been summarized + In depth analysis of core test sites , Let your second change offer harvester .

Due to space reasons, it is divided into two parts :
turn to :2022 Nian Dachang Android Summary of interview questions ( Two )( With answers )

Android The real question of the interview

1. Several ways to communicate across processes

Intent, For example, make a phone call
ContentProvider The database stores data
Broadcast Broadcast communications
AIDL signal communication , Share data through interfaces

2.wait and sleep The difference between

wait yes Object Methods ,wait It's the object lock , The lock method does not allow execution to continue , When executed notify Method will continue to be implemented after ,sleep yes Thread Methods ,sleep Is to sleep the thread , Give up cpu, Automatically continue execution after completion

3.String,StringBuffer,StringBuilder The difference between

String Do not change the object , Once created, it cannot be modified

String str=“aaa”;
str=“bbb”;
Although the above code has changed str, But the implementation process is recycling str, Assign value to a new str
StringBuffer After creating , You can modify
StringBuilder You can also modify , The efficiency of execution is higher than StringBuffer, unsafe
When character assignment is used less String
Character assignment is frequently used StringBuilder
When multiple threads synchronize operation data , Use StringBuffer

4.View and SurfaceView The difference between

View Refresh based on main thread UI,SurfaceView The sub thread can refresh UI

5.View The principle of drawing

View Base class for all graphic controls ,View Drawn by 3 Functions complete
measure, Calculate the size of the view
layout, Provide the location of the view to display
draw, draw

6. sketch JNI

yes java and c The bridge between languages , because java It's a semi explanatory language , Can be decompiled , An important security related code is used C Programming , And many of the underlying function calls C Language has come true Java There's no need to make wheels again , So it defines JNI Interface implementation

7. sketch TCP,UDP,Socket

TCP Is a 3 The second handshake ,4 Complete the transmission of a series of data with one wave
UDP It's disconnected , know IP Address and port number , Just send it data , Whether or not the data is sent successfully
Socket It's a different kind of computer , Real time connection , For example, sending documents , im

8. Audio and video related

On the whole , There are several categories
Video recording ,Camear Camera recording video class ,MediaProjection Screen recording video class
Encoding aspects ,MediaCodec,MediaRecorder
Preview aspect ,SurfaceView,GLSurfaceView,TextureView,VideoView

9. Difference between process and thread

Concept : Processes include multiple threads , A program a process , The advantage of multithreading can improve the efficiency of execution , Improve resource utilization
establish :Thread Classes and Runnable Interface ,
Common methods are :
start() Used to start threads
run() Call... In the thread object run Method
join() Merge queue to current thread
sellp() Sleep release cpu resources
setPriority() Set thread priority

10. How to view and solve memory leaks

Concept : Some objects have a limited life cycle , When their task is done , They will be recycled , If at the end of the object's life cycle , This object is also referenced by a series of , This will cause memory leaks .
resolvent : Using open source framework LeakCanary Detection targeted solution
Common memory leaks are :
Memory leak caused by single instance , For example, in a single example Context The life cycle is greater than itself Context Life cycle
Thread usage Hander Caused by memory shackles , When activity It's already over. , The thread is still running the update UI
Non static classes use static variables to cause non recyclable releases resulting in leaks
WebView Too many pages cause memory leaks
The resource is not closed, causing leakage , For example, close the connection after using the database

11.View The distribution mechanism of , Slide conflict

View The order of event delivery is 3 An important way ,dispatchTouchEvent() Whether this event has been consumed ,onInterceptTouchEvent() Did you intercept this incident ,onTouchEvent() Whether to deal with this incident , Sliding conflict can be divided into sliding conflict in the same direction , for example ScrollView and ListView, Sliding in the same direction conflicts , You can calculate ListView Height and dynamic settings ListView Height ,ScrollView Highly variable . for example ViewPager and ListView, Sliding conflicts in different directions , One is horizontal sliding and the other is vertical sliding , Sliding in different directions can be judged by x,y Is the axis sliding horizontally or vertically , If it's judged to be a lateral slide , Just intercept ListView Events , Vertical is the opposite .

12.RecyclerView and ListView The difference between

On Cache : The former caches View+ViewHolder+flag, No need to call findViewById, The latter is just caching View
Refresh data , The former provides local refresh , The latter is all refreshed

13.recyclerView Nesting carton solves how to solve

Set the number of preloads LinearLayoutManager.setInitialPrefetchItemCount(4), The default is preload 2 individual ,
Set sub item cache ,
Set the built-in slide conflict resolution property rv.setHasFixedSize(true); rv.setNestedScrollingEnabled(false);
It can be solved perfectly , however Google Not recommended RecyClerView Nesting uses , Nesting is needed to try to look like ExpandableListView Third party controls to solve

14, To talk about MVC ,MVP,MVVM

MVC:View It's directly accessible Model Of ! thus ,View It will contain Model Information , It's inevitable to include some Business logic . stay MVC In the model , Pay more attention to Model Invariability of , And there are multiple pairs at the same time Model Different displays of , And View. therefore , stay MVC In the model ,Model Don't depend on View, however View It depends on Model Of . More Than This , Because there are some business logic View It's done in , Cause to change View It's also more difficult , At least those business logic can't be reused .
MVP:MVP It's from the classic model MVC Evolved , Their basic ideas have something in common :Controller/Presenter In charge of logical processing ,Model Provide data ,View negative Responsibility display . As a new model ,MVP And MVC There is a big difference : stay MVP in View Not directly used Model, The communication between them is through Presenter (MVC Medium Controller) To carry out , All the interactions take place in Presenter Inside , And in the MVC in View From the direct Model Instead of reading data through Controller.
MVVM: Data bidirectional binding , Drive... With data UI,M Provide data ,V View ,VM That is, the data-driven layer

15.dagger2

Dagger2 Is a framework mainly used for dependency injection , Reduce initialization object operations , Reduce coupling

16Android performance optimization

Layout optimization : Reduce layout levels , Use ViewStub Speed up the display , Layout and take , Use... As little as possible warp_content, Delete useless properties in space , Avoid over drawing to remove window Default background , Display booth map on demand , Customize View Optimize , Use canvas.clipRect() Identify visible areas
Starting speed : With distributed loading , Load asynchronously , Delay loading improves application initialization speed , Use thread to initialize data, etc , Reasonable refresh mechanism
Memory aspect : Prevent memory leaks , Use some third-party tools to detect and solve
Code optimization : follow Java Life cycle
Package optimization : Delete useless resources , Optimize pictures , Code obfuscation , Avoid duplicate libraries , pluggable

17.Hander principle

Handler,loop Polling detection sends messages to MessagerQuery,MessageQuery Yes Message List ,Handler Callback method processing message , rewrite handMessage Method refresh ui

18.SharedPreference How about cross process usage ? How to ensure the security of cross process use ?

In two applications manifest The same in configuration shartdUserId attribute ,A The application saves data normally ,B application
createPackageContext(“com.netease.nim.demo”, CONTEXT_IGNORE_SECURITY)
obtain context Then get the application data , To ensure data security , Use encrypted storage

19. How to improve the push arrival rate

Cell phone system , Xiaomi uses Xiaomi to push , Huawei uses Huawei push , Other mobile phones are pushed by UFIDA

20.activity,fragment Value transfer problem

adopt Bundle Pass value , stay activty Define variable values , Expand fragment Create value transfer

21.activity And fragment difference

Life cycle :
fragment From creation to destruction, the whole life cycle is onAttach()→onCreate()→onCreateView()→onActivityCreated()→onStart()→onResume()→onPause()→onStop()→onDestroyView()→onDestroy()→onDetach()
And activity The different ways are
onAttach(): When Fragment and Activity Call... When establishing an association ;
onCreateView(): When Fragment Create view call ;
onActivityCreated: And Fragment The associated Activity complete onCreate() Then call ;
onDestoryView(): stay Fragment Called when the layout in is removed ;
onDetach(): When Fragment and Activity Call when disassociating ;
activity There are only a few common life cycles ;
onCreate(): Express Activity Being created , Often used to Initialization work , For example, call setContentView Load interface layout resources , initialization Activity Required data, etc ;
onRestart(): Express Activity Restarting , In general , At present Acitivty From invisible to visible again ,OnRestart It will be called ;
onStart(): Express Activity Is being activated , here Activity Visible but not at the front desk , Still backstage , Can't interact with users ;
onResume(): Express Activity Focus of attention , here Activity Visible and at the front desk and start the activity , This is the onStart The difference is ;
onPause(): Express Activity Stopping , We can do some at this time Store the data 、 Stop animation, etc , But not too time consuming , Because it will affect the new Activity Display of ,onPause It has to be done first , new Activity Of onResume Will execute ;
onStop(): Express Activity About to stop , You can do a little heavy recycling , Like logging off the radio receiver 、 Turn off network connections, etc , It can't be too time consuming ;
onDestroy(): Express Activity About to be destroyed , This is a Activity The last callback in the lifecycle , Often do Recycling work 、 Release resources ;
difference :
Fragment Than Activity Four more callback cycles , More flexible control and operation ;
Fragment Can be in xml Write directly to the file , It can also be in Activity Add dynamically in ;
Fragment have access to show()/hide() perhaps replace() Yes Fragment Switch , There is no obvious effect when switching ,Activity When switching, there will be obvious page turning or other effects ;

22.Fragment in add And replace The difference between ?

add Will not reinitialize fragment,replace Every time ;
Add the same fragment when ,replace There will be no change ,add Will be submitted to the IllegalStateException abnormal ;
replace First remove Drop the same id All of the fragment, And then in add The current one fragment, and add It's covering the previous one fragment. So if you use add Usually accompanied by hide() and show(), Avoid overlapping layouts ;
Use add, If the app is in the background , Or otherwise destroyed by the system , When you turn it on again ,hide() It is quoted in fragment Will destroy , So there will still be layout overlap bug, have access to replace Or use add when , Add one tag Parameters ;

23.FragmentPagerAdapter And And FragmentStatePagerAdapter The difference with the use of scenarios ?

FragmentPagerAdapter Each Fragment It will last forever in FragmentManager in , As long as the user can return to the page , It's not going to be destroyed . So it applies to those data Relatively static pages ,Fragment It's also a small number ;FragmentStatePagerAdapter Keep only the current page , When the page is not visible , The Fragment It will be eliminated , Release its resources . So it applies to those The data is dynamic 、 It takes up a lot of memory , many Fragment The situation of ;

24. Under the said Activity Four startup modes of 、 Application scenarios ?

standard The standard model : One at a time Activity Will recreate a new instance , Whether this instance already exists or not , The Activity By default, it will enter the Activity In the task stack ;
singleTop Stack top reuse mode : If new Activity Already at the top of the task stack , Then this Activity Will not be recreated , At the same time, it will callback onNewIntent Method , If new Activity Instance already exists but not at the top of the stack , that Activity It will still be recreated ;
singleTask In stack reuse mode : as long as Activity There is... In a task stack , So many times start this Activity Will not recreate the instance , And callback onNewIntent Method , This mode starts Activity A, The system first looks for the existence A Desired task stack , If it doesn't exist , A new task stack will be created , And then create A Put the instance of into the stack ;
singleInstance Single instance mode : It's a kind of reinforcement singleTask Pattern , With this pattern Activity Can only be in a single task stack , And there is only one instance in this task stack ;

25. Under the said Activity Follow Follow window , view The relationship between ?

Activity Created by attach() I've initialized one Window That is to say PhoneWindow, One PhoneWindow Hold one DecorView Example ,DecorView Itself is a FrameLayout, Inherited from View,Activty adopt setContentView take xml Layout controls are constantly addView() Add to View in , Finally, it shows Window For us to interact ;

26. Horizontal and vertical screen switching Activity Life cycle change ?

Not set up Activity Of android:configChanges when , Cutting the screen will destroy the current Activity, Then reload the call lifecycles , It will be executed once when cutting the horizontal screen , When cutting the vertical screen, it will execute twice ;onPause()→onStop()→onDestory()→onCreate()→onStart()→onResume()
Set up Activity Of android:configChanges=" orientation", After the model test
stay Android5.1 namely namely API 3 23 Below grade , Cutting the screen will still recall each life cycle , Cut across 、 It will only be executed once when the screen is up
stay Android9 namely namely API 8 28 Below grade , Cutting the screen will not recall each life cycle , Only execute onConfigurationChanged Method
After the official correction , The original words are as follows
If your application is for Android 2 3.2 namely namely API Level 3 13 Or more
High level ( according to minSdkVersion and targetSdkVersion)

To be continued …

Last

Actually Android There are so many knowledge points in development , There are still so many things to ask about in the interview . So there's no other trick to an interview , It depends on how well you are prepared for these knowledge points .
At present, there is still a lack of senior engineers , A lot of senior positions pay really high salaries ( A lot of money doesn't necessarily mean you can find the right one ), So it's important to try to be a senior engineer .

Attached here are dozens of sets of bytes related to the above interview questions , JD.COM , millet , tencent 、 headlines 、 Ali 、 Meituan and other companies 19 Interview questions for . Put the technical points into video and PDF( In fact, it took a lot more energy than expected ), Contains the context of knowledge + A lot of details .

【 Details can be sorted and scanned, and the QR code below can be obtained for free 】

原网站

版权声明
本文为[Code is not difficult to write]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060938118046.html