The programmer lamented that the Android R&D interview was so difficult.

Preface

I don’t know how long you have not participated in an interview. The interviews during this period of time are really stricter than the other!

Yesterday, I participated in the technical side of a major factory and scared me on the spot. I didn't expect it to be so difficult!

If you don’t believe me, you can die too:

  • Draw the general architecture diagram of Android
  • Please describe what happened after you clicked the build button of Android Studio, and roughly explain what happened when an application was installed on the phone;
  • Have a basic understanding of Dalvik and ART virtual machine;
  • How does Inter-Process-Communication on Android work when communicating across processes;
  • How is the app sandboxed and why should it be done;
  • Authority management system (how the underlying authority is granted)
  • The life cycle of the process and Application;
  • Linked list reversal
  • Dynamic permission adaptation scheme, the concept of permission groups
  • Network request cache processing, how okhttp handles network cache

You say that the interviewer is not ruthless! Too ruthless!

For us programmers, the interview is to express what we have learned to the interviewer. When I was going to school and looking for a job, I found that the first person to find a job was not the best skilled person but a highly active person who was good at communicating. The complaint I heard most was " Why I know this thing clearly , but I didn't know it during the interview." Where do I start ".

This article will start from my own experience and talk about how to fully prepare before the interview, how to express one's skills fluently, and how to enter the project from being at a loss and blindly starting to calm down later.

Preparation before the interview

Below I will share the preparation before the interview from the following aspects.

1. Position yourself
First of all, you must position yourself, at what stage you are now, whether you are a junior, intermediate, senior, or expert. Under normal circumstances, when you first started working for a year or so, if you try to improve yourself for about two years, you will be intermediate, three to five years advanced or even expert. The premise is to keep studying.

2. Sorting out the knowledge.
Because I position myself as a senior development engineer, as the saying goes: Interview and repair aircraft carriers, work screws. The interview considers all aspects. For Android, there are mainly the following aspects to prepare: Java foundation, Android foundation, Java concurrency, Java virtual machine, Android source code (including framework and open source projects), data structure and algorithm. Of course, after sorting out the basic knowledge, you have to read some interview scriptures to see the latest questions asked by various manufacturers. In fact, after preparing the above things, if the foundation is good, it will take about a month, if the foundation is not good, it will take at least 3 months.

As the saying goes, do not fight unprepared battles, only when you are ready can you get good results in the interview process.

3. Preparation of resume

Resume is a stepping stone, and HR receives many resumes every day. How to make a resume shine, and can grasp the key information at a glance: personal basic information (name, phone number, email address, graduate school, etc.), work experience, skill points, and some highlights (such as the sixth certificate, awards, etc.). The resume should be concise and clearly structured. After writing your resume, you need to update your resume on the recruitment website.

4. Various channels for interview opportunities.
This interview passed a total of 3 channels, one is friends introductory, the second is headhunting help, and the third is delivery through boss or Zhilian.

  • Incoming friends: You must first get to know some friends in the circle. Employees of various manufacturers can add friends through pulses, or through technical exchanges, learn about friends’ dynamics, and let them recommend them. Of course, there are two ways to find introductory. The first is to ask a friend to recommend a position and ask him to help ask if there is a shortage of people in the group. The second way is to find it by yourself. Under normal circumstances, the company's job fair will display the join us link on the official website, where you can see the job information. The second recommendation is to find a position by yourself, send it to a friend, and ask him to directly help recommend this position. Recommendations generally have bonuses.
  • Headhunting help: I ​​recently listened to a course "How to Effectively Improve Competitiveness in the Workplace". I think what the teacher said is particularly good. Don't reject headhunting and treat headhunting as your partner. The headhunter knows the recommended company better than you and the current market. There are also many ways to find headhunters. The first is to ask your friends if they have cooperated with reliable headhunters. The second is to find a lot of headhunters like Zhaopin Recruitment, Hunting and Boss Direct Recruitment. After you update your resume, a headhunter will contact you.
  • Recruitment website: Internet recruitment is on the hook, boss, and Zhilian. The resume is updated to the website, and then it can be delivered. Here you need to see whether the resume delivery is effective. If no one checks your resume for a long time, then it means that there is a problem with your resume. Please revise it and deliver it in time.

5. Skill reserve

  • One to two years after graduation:

The basic knowledge of Java needs to be mastered: object-oriented understanding, basic types and reference types, construction methods, commonly used classes (inner classes, anonymous classes, abstract classes), three major features (encapsulation, inheritance, polymorphism), rewriting And overloading, interface and interface realization, etc. The interviewer will ask you these questions at the level of mastery, mainly to check whether your basic knowledge is solid, after all, Android is written in Java.

Android needs to master: the simple use of the four major components, the life cycle of the activity, the binding of the fragment, the value transfer between the activity and the fragment, the implementation of the recyclerview implementation list Jiugongge waterfall flow layout, the reuse problem of the viewHolder, The characteristics of several ways of data storage, the use of commonly used frameworks Glide, Retrofit, eventBus, and butterknife.

  • Two to three years after graduation:

The basic knowledge of Java needs to be mastered: For two to three years of Android programmers, Java is not just about using some basic knowledge, but also having its own understanding while using it. For example, for packaging, the interviewer will not ask you what packaging is, but what code/function of the company you have packaged, and how you packaged it. At this time, the investigation is whether you can write code or only imitate code. If you have not encapsulated the code in your project, you can read the source code of some excellent frameworks on the Internet to learn how others encapsulate it.

Of course, not only encapsulation, but also many knowledge points must be mastered in accordance with this requirement, such as: Java generics, reflection, collection framework, interfaces and abstract classes, design patterns, and so on. To master these, besides watching video learning, you can also read some excellent source code. If you don’t understand, check the blog again. After you understand it thoroughly, you must use it on your own project. Only then can you be impressed with your studies.

Android needs to master: APP startup principle, if you want to know more about it, you can read my other chat (App startup principle and startup optimization detailed explanation), image compression and performance optimization, custom view, event distribution process, screen adaptation Configuration, componentization and plug-inization, Glide's caching and reuse, OkHttp's responsibility chain and connection pool, serialization and deserialization, analysis of the source code of a framework you are most proficient in, etc. It can be seen that for two to three years programmers not only have more knowledge points, but also need to have a certain understanding of the principles.

Interview experience sharing, the difference between a large factory and a small factory

Dachang interview experience

When I first came out to look for a job, I interviewed many companies. At that time, it was the explosive period of mobile development. Among them were Tencent and other medium and large companies as well as some small companies that were just starting up. Of course, the big companies eventually failed the interview. I remember that when I went to Tencent for an interview, there were a lot of people who went to the interview, and they needed to wait in the lobby. They went to the interview in batches. First, the group interviews. After understanding the basic situation, they were alone to wait for the interview. A total of three rounds of interviews, interviewers The time when the interview result will come out will be notified.

The questions the interviewer asked were: Why did you leave from the last company, how do you view our company, what is your future career plan, and how to optimize the start-up optimization in terms of technology? How to transfer large memory data across processes? How does the main thread wait for all threads to finish executing before performing a specific task? Have you seen the principle and source code? How do you implement the rxpay and rxlogin?

The difference between large and small factories

  • Big factory:

There are many processes, usually there are more than three sides. First, there will be a set of interview questions waiting for you. Of course, not all companies have interview questions, but the probability of having interview questions is higher for large companies. Secondly, technical supervisors interview, and then technical managers. During the interview, the personnel will introduce you to the company’s development, business, company benefits, working hours, etc. The development of large factories is generally divided into modules, each person is responsible for a certain module, so you are required to have your own advantages, for example, you can write custom components, video modules, and have a deep research on NDK.

  • Small factory:

There are few processes, and you may be called to work as soon as you pass. Small companies must ask when the salary will be paid during the interview. The early payment indicates that the company has sufficient funds. It is normal to pay in the middle of the month. If the company is short of funds at the end of the month, a financial crisis may occur. There are also five insurances and one housing fund, and if so, is there a trial period? At present, some companies do not have the five insurances and one housing fund, and most companies do not pay the five insurances and one housing fund during the trial period. Regarding the importance of the five social insurances and one housing fund, you can go to Baidu to search for a search. This becomes even more important after the purchase restriction order comes out.

The difference in technology is that small companies are generally developed by one person, requiring you to know the development process of the entire project, but the technical depth is not high (only for junior programmers, senior architects will say otherwise). Before the interview, prepare more projects to demonstrate. Some people say that those who understand the technology don’t look at the works, but it is different for small companies. It is possible that the interviewers are product managers, back-office personnel, etc., and they don’t know much about Android. Deep, there are a few good presentations at this time, which will definitely add a lot of points to your interview.

Analysis of knowledge points frequently asked in Android interviews

The following five questions have been asked during the interview, and I have also looked at others as an interviewer. They are more representative questions.

Communication method between activities

1) Pass parameter jump through Intent

2) Via broadcast

3) Callback via interface

4) With the help of static variables or global variables of the class

5) With the help of SharedPreference or external storage, such as database or local file

Please introduce the Android data storage method

Use SharedPreferences to store data; file to store data; SQLite database to store data; use ContentProvider to store data; network to store data.

The directories corresponding to Preference, File, and DataBase are /data/data/Package Name/Shared_Pref, /data/data/Package Name/files, /data/data/Package Name/database.

  • Use SharedPreferences to store data

First explain the storage method of SharedPreferences, which is a mechanism provided by Android to store some simple configuration information, such as the user name and password of the logged-in user. It uses the Map data structure to store data, which is stored in a key-value manner, which can be easily read and written. The specific examples are as follows:

void ReadSharedPreferences(){String strName,strPassword;SharedPreferences   user = getSharedPreferences(“user_info”,0);strName = user.getString(“NAME”,””);strPassword = user getString(“PASSWORD”,””);}void WriteSharedPreferences(String strName,String strPassword){SharedPreferences   user = getSharedPreferences(“user_info”,0);uer.edit();user.putString(“NAME”, strName);user.putString(“PASSWORD” ,strPassword);user.commit();}

The methods of reading and writing data are very simple, but there are some differences when writing: first call edit() to make it in the editing state, and then modify the data, and finally use commit() to submit the modified data. In fact, SharedPreferences uses XML format to store data in the device, under /data/data//shares_prefs in File Explorer in DDMS. There are some restrictions on using SharedPreferences: it can only be used within the same package, and cannot be used between different packages.

  • File storage data

File storage is a more commonly used method. The method of reading/writing files in Android is exactly the same as the program that implements I/O in Java. OpenFileInput() and openFileOutput() methods are provided to read Files on the device. Specific examples are as follows:

String fn = “moandroid.log”;FileInputStream fis = openFileInput(fn);FileOutputStream fos = openFileOutput(fn,Context.MODE_PRIVATE);

  • Network storage data

For network storage, you need to deal with Android network data packages. For detailed instructions on Android network data packages, please read Which packages of the Java SDK are referenced by the Android SDK? .

What are the startup modes of activity? What does it mean?

In Android, there are 4 activity startup modes, namely:

"Standard" (default)

“singleTop”

“singleTask”

“singleInstance”

They are mainly different as follows:

  • How to determine the task

The target task of "standard" and "singleTop" activity is in the same task as the sender of the received Intent, unless the intent includes the parameter FLAG_ACTIVITY_NEW_TASK.

If the FLAG_ACTIVITY_NEW_TASK parameter is provided, it will start in another task.

"SingleTask" and "singleInstance" always regard activity as the root element of a task, and they will not be launched into another task.

  • Whether to allow multiple instances

"Standard" and "singleTop" can be instantiated multiple times and exist in different tasks, and a task can include multiple instances of an activity.

"SingleTask" and "singleInstance" are restricted to generate only one instance, and are the root element of the task. singleTop requires that if there is already an instance of the Activity to be created at the top of the stack when the intent is created, the intent will be sent to the instance instead of the new instance.

  • Whether to allow other activities to exist in this task

"SingleInstance" monopolizes a task, and other activities cannot exist in that task; if it starts a new activity, regardless of the launch mode of the new activity, the new activity will run in other tasks (as if FLAG_ACTIVITY_NEW_TASK was added) parameter).

The other three modes can coexist with other activities.

  • Whether to generate a new instance every time

"Standard" will generate a new instance of activity for every start Intent.

If the activity of "singleTop" is at the top of the task stack, no new instance of the activity is generated, and the instance at the top of the stack is used directly, otherwise, an instance of the activity is generated.

For example, now the task stack element is ABCD (D is on the top of the stack), and then a startup intent is sent to D. If D is "standard", a new instance of D will be generated, and the stack will become A-B-C-D- D.

If D is singleTop, no new instance of D will be produced, and the stack state will still be ABCD.

If an Intent is sent to B at this time, no matter whether B's launchmode is "standard" or "singleTop", a new instance of B will be generated, and the stack state will change to ABCDB.

"SingleInstance" is the only activity in its stack, and it will be reused every time.

If "singleTask" is at the top of the stack, accept the intent, otherwise, the intent will be discarded, but the task will still return to the foreground.

When an existing activity instance processes a new intent, the onNewIntent() method will be called. If an activity instance is generated after receiving the intent, the user can return to the previous state by pressing the back key; if it is an existing activity, the intent is processed Otherwise, the user cannot return to the previous state by pressing the back key.

Talk about the relationship between ContentProvider, ContentResolver, ContentObserver

ContentProvider realizes data sharing between various applications and is used to provide content for other application operations. If the ContentProvider is used in the contact application, you can read and modify the contact information in your own application, but you need to obtain the corresponding permissions. It is also just a middleware, the real data source is files or SQLite, etc. ContentResolver content resolver, used to obtain the data provided by the content provider, send a message through ContentResolver.notifyChange(uri) ContentObserver content listener, can monitor the change state of the data, observe the database changes caused by a specific Uri, and then do some corresponding processing , Similar to the trigger in the database, when the Uri observed by ContentObserver changes, it will be triggered.

There are several ways to register for broadcasting. What are the advantages and disadvantages of these ways? Please talk about Android's intention to introduce the broadcast mechanism.

First write a class to inherit BroadcastReceiver

The first type: declare in the manifest file, add

The second use code to register such as

The difference between the two registration types is:

  1. The first is not a resident broadcast, which means that the broadcast follows the life cycle of the program;
  2. The second is the resident type, which means that when the application is closed, if there is information broadcast, the program will be called by the system to run automatically.

The current mainstream framework sharing, how to quickly get started with the project

Build the mainstream framework set for the project

Dagger2+RxJava+Retrofit+MVP is the framework set I currently use, which is widely used at present, and the combination of the four forms the beautiful overall structure of the project. Packages that need to be imported

>  dependencies {    // 网络请求    compile 'com.squareup.retrofit2:retrofit:2.1.0'    compile 'com.squareup.retrofit2:adapter-rxJava:2.0.1'    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'    compile 'com.squareup.retrofit2:converter-scalars:2.0.0-beta4'    compile 'com.squareup.okhttp3:okhttp:3.2.0'    //  注解    compile 'com.google.dagger:dagger:2.0.2'    apt 'com.google.dagger:dagger-compiler:2.0.2'    provided 'org.glassfish:Javax.annotation:10.0-b28'    compile 'com.jakewharton:butterknife:7.0.1'    // Rx    compile 'io.reactivex:rxandroid:1.1.0'    compile 'io.reactivex:rxJava:1.1.5'    }

Below is the architecture diagram of MVP

As shown in FIG

View and Model do not directly interact, but use Presenter as a bridge between View and Model.

Among them, the Presenter holds a reference to the Interface of the view layer and the Model layer at the same time, and the View layer holds a reference to the Interface of the Presenter layer. When an interface of the View layer needs to display some data, an interface of the Presenter layer will be called first, and then the Presenter layer will call the Model layer to request data.

When the Model layer data is successfully loaded, the callback method of the Presenter layer will be called to notify the presenter layer that the data is loaded.

Finally, the Presenter layer calls the interface of the View layer to display the loaded data to the user. This is the entire core process of the MVP model. If you are interviewing for junior Android development, the interviewer should only ask you to explain the entire call process, as long as you can smoothly say that the entire process should be almost the same.

Flow chart of Dagger2

What is Dagger2

Dagger2 is a dependency injection framework, and butterknife is also a dependency injection framework. But butterknife is called butter knife at most. Dagger2 is called a sharp weapon. Its main function is to manage objects, and its purpose is to reduce program coupling.

Advantages of Dagger2

  • Simple access to global object instances

Like the ButterKnife library that defines views, event handling, and resource references, Dagger2 provides easy access to global object references. All instances where singletons are declared can be accessed using @inject. For example, the following examples of MyTwitterApiClient and SharedPreferences:

> public class MainActivity extends Activity { @Inject  MyTwitterApiClient mTwitterApiClient;  @Inject SharedPreferences sharedPreferences; public void onCreate(Bundle savedInstance) {     // assign singleton instances to fields     InjectorClass.inject(this); }

  • Complex dependencies only require simple configuration

Dagger2 will pass dependencies and generate easy-to-understand and easy-to-analyze code. Object references in a large number of template codes that have been handwritten before will be created by it for you and passed to the corresponding objects. So you can pay more attention to what is built in the module rather than the order in which the object instances are created in the module.

  • Make unit testing and integration testing more convenient

Because the dependencies have been separated for us, we can easily extract different modules for testing. Dependency injection and configuration are independent of components. Because the object is initialized in an independent, uncoupled place, when injecting abstract methods, we only need to modify the implementation method of the object, without major changes to the code base. Dependencies can be injected into a component: we can inject mock implementations of these dependencies, which makes testing easier.

  • Scoped instances

Not only can we easily manage global instance objects, but we can also use the scope in Dagger2 to define different scopes. (For example, according to the life cycle of user session and activity)

  • What is Retrofit

Retrofit is an Android and Java REST client library developed by Square. This library is very simple and has many features. Compared with other network libraries, it is easier for beginners to quickly grasp.

  • How to create a Retrofit instance

When creating a Retrofit instance, you need to use Retrofit.Builder and call the baseUrl method to set the URL.

Interface definition

Take the time list as an example

>  public interface TimeService {>  @GET("getTimes?")    Call< ResponseBody > getTimes (@Query("month") String month);}

Note that interface is not a class, so we cannot directly call this method. We need to use Retrofit to create a TimeService proxy object.

TimeService timeService= createRetrofit().create(TimeService .class);

Interface call

> Call<ResponseBody> mService= timeService.getTimes ("1");        mService.enqueue(new Callback<ResponseBody>() {            @Override            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {                try {                    Log(response.body().string());                } catch (IOException e) {                    e.printStackTrace();                }            }            @Override            public void onFailure(Call<ResponseBody> call, Throwable t) {                t.printStackTrace();            }        });

How to quickly understand the project for secondary development

When we work in a new company, we may not take over a new project but maintain a project developed by others. We don't know where to start when facing a huge project. What I want to tell you here is that when you get the project, don't develop blindly but read the source code of the project. To read the source code, first browse the project structure,

Through this structure diagram, you can understand that the project uses the MVP architecture. There are two libs, one related to service and one related to image processing. Then read the build.gradle file, which contains the reference address of the third-party library used in the project, and know which technologies are used in the project. If you have an unfamiliar third-party library, you can find resources based on this address to familiarize yourself with the project. For the modules used in the library, we will gradually study the source code and implementation principles of the library in the future. When these are almost understood, take a look at the requirements document and design diagram, walk through the process against the requirements, mainly record the jump between activities, you can draw a structure diagram of the jump between classes, so that the whole jump The logic will be clearer.

There are two more worth reading: the tool classes in the project and the packaged components. I believe that many people have encountered it and found a way to process data on the Internet for a long time. After many days, I found that there are tools in the project that can be used directly. Packaged components are similar to tools and can be used directly. In the future development, we also encourage everyone to componentize the project.

Summary of interview questions from major manufacturers over the years

Tencent Map

  • Algorithm: non-recursive realization of binary tree preorder traversal;
  • Handwriting: Double check singleton class (where the volatile keyword is used)
  • GreenDao low-level implementation
  • The use and principle of binder
  • Use and principle of messager
  • Memory leaks in Android
  • oom reason and how to locate it
  • How to reduce the rate of program crashes
  • okhttp source code understanding, the use and benefits of using interceptors
  • Difficulties in the project
  • Componentization, plug-inization
  • ExoPlayer source code
  • Picture optimization, how to compress, how to cache

Alibaba

  • LRUCache principle
  • Image loading principle
  • Modular implementation (benefits, reasons)
  • Video encryption transmission
  • Statistics start time, standard
  • How to maintain the stability of the application
  • ThreadLocal principle
  • Talk about classloader
  • Dynamic layout
  • Hot repair, plug-in
  • HashMap source code, SpareArray principle
  • Performance optimization, how to ensure that the application startup does not freeze
  • Is the SP process synchronized? Is there any way to synchronize
  • Introduce SurfView
  • HashMap realization principle, ConcurrentHashMap realization principle
  • BroadcastReceiver, LocalBroadcastReceiver classification
  • Bundle mechanism
  • Handler mechanism
  • android event delivery mechanism
  • List of operations between threads
  • App startup process, starting from clicking on the desktop
  • Dynamic loading
  • Class loader
  • OSGI
  • Https request slow solution, DNS, carry data, direct access to IP
  • GC recovery strategy
  • Draw the general architecture diagram of Android
  • Describe what happened after clicking the build button of Android Studio
  • In general, explain what happens when an application is installed on the phone;
  • Have a basic understanding of Dalvik and ART virtual machine;
  • How does Inter-Process-Communication on Android work when communicating across processes;
  • How is the app sandboxed and why should it be done;
  • Authority management system (how the underlying authority is granted);
  • The life cycle of the process and Application;
  • System startup process Zygote process -> SystemServer process -> various system services -> application process

Meituan

  • Thread suspension, sleep, resource release related, wake up, thread synchronization, data transfer, I asked a lot of thread questions, about 20 minutes
  • Multi-threaded access and function of static synchronized methods, two synchronized methods in the same class, two threads access at the same time
  • Inner classes, static inner classes and anonymous inner classes, and applications in the project
  • What is generic and its application in the project
  • The handler sends a message to the child thread, how to start the looper
  • Delivery of down, move, up events
  • activity stack
  • How to know the size of the view when encapsulating the view
  • intent-filter
  • The difference between arraylist and linkedlist, and application scenarios
  • How to start the service, how to exchange data between service and activity
  • Does the drop-down status bar affect the life cycle of the activity? If a network request is made during onStop, how to resume during onResume
  • view rendering

IQIYI

  • Android message mechanism
  • Android View drawing process, what is executed when a TextView instance calls the setText() method
  • Optimization and upgrade points of Android dalvik virtual machine and Art virtual machine
  • Android screen rendering mechanism
  • The principle of hot repair, which kinds of hot repair frameworks you have known
  • Principle of OkHttp
  • The realization principle of Android thread pool
  • JavaGC mechanism
  • The realization mechanism of HashMap, how to HashMap thread safety
  • What is the definition of reentrant locks, fair locks and unfair locks?
  • What commonly used data structures have you used, and how do you understand the tree?
  • Activity startup mode, the characteristics of allowReparent and stack affinity
  • WebView optimization
  • Do you have any experience using Jni
  • Have you used RxJava?
  • Tell me about your understanding of design patterns, which design patterns are mainly used in the development process?
  • Quickly write about it, do you understand dynamic programming?

to sum up

There are more investigations on basic knowledge, focusing on principles, and requiring interviewers to deepen their understanding when learning technology. Different companies have different business focus, but the overall skills that need to be mastered are: advanced UI, performance optimization, mobile architecture, etc.

At last

Thank you for your patience and reading my long-winded article.

I would like to communicate and learn from each other and make progress together with all compatriots who are sticking to the Android development position!

All the study materials and interview answers of the article have been sorted into PDF documents, as shown in the figure below:image

Friends in need can click here to get it for free . In addition, the editor here has a collection of Android learning PDF + architecture video + interview document + source code notes , as well as advanced architecture technology advanced brain maps, and Android development interview special materials. , The advanced advanced framework information helps everyone learn to improve the advanced level, and also saves everyone’s time to search for information on the Internet. You can also share it with friends around you to learn together. It is also free to share with everyone. Click here to jump directly to the way to receive .

Guess you like

Origin blog.csdn.net/Android578/article/details/115124565