Android development for 2 years, after outsourcing, interviewing more than a dozen small and medium-sized factories and finally getting offers, Android primary interview questions are summarized!

1. Several ways of cross-process communication

Intent, such as making a phone call,
ContentProvider database storage data
Broadcast broadcast communication
AIDL communication, sharing data through the interface

2. The difference between wait and sleep

Wait is a method of Object, wait is an object lock. The locked method will not continue execution. When the notify method is executed, it will continue to execute. Sleep is the method of Thread. Sleep is to sleep the thread, give up the cpu, and automatically continue execution after the end.

3. The difference between String, StringBuffer, StringBuilder

String cannot be changed, once created, it cannot be modified

String str="aaa";
str="bbb";

Although the above code changes str, the execution process is to reclaim str and assign the value to a new str.

After the StringBuffer is created, you can modify the StringBuilder or modify it. The execution efficiency is higher than that of StringBuffer, which is not safe. String is used less when character assignment, StringBuilder is frequently used when character assignment, and StringBuffer is used when multiple threads operate data synchronously.

4. The difference between View and SurfaceView

View refreshes the UI based on the main thread, and SurfaceView sub-threads can refresh the UI

5. View drawing principle

View is the base class of all graphic controls, and the drawing of View is completed by 3 functions

measure, calculate the size of the view;
layout, provide the position of the view to be displayed;
draw, draw.

6. Briefly describe JNI

It is a bridge between java and c language. Since java is a semi-interpreted language, it can be decompiled. C programming is used for a kind of code that is important to safety. In addition, many underlying functions call C language to implement Java There is no need to reinvent the wheel, so the implementation of the JNI interface is defined.

7. Briefly describe TCP, UDP, Socket

TCP is a three-way handshake and four waved hands to complete a series of data transmission. UDP is connectionless. You can send data to it if you know the IP address and port number, regardless of whether the data is sent successfully.

Socket is a different computer, real-time connection, such as file transfer, instant messaging.

8. Audio and video related categories

Generally speaking, it is divided into several categories:

  • Video recording, Camear camera recording video category, MediaProjection screen recording video category
  • Encoding, MediaCodec, MediaRecorder
  • In terms of preview, SurfaceView, GLSurfaceView, TextureView, VideoView

9. The difference between process and thread

Concept: A process includes multiple threads, one process per program, and the advantages of multithreading can improve execution efficiency and resource utilization.

Create: Thread class and Runnable interface;

Common methods are:

  • start() is used to start the thread
  • run() calls the run method in the thread object
  • join() merge the queue to the current thread
  • sellp() Sleep release cpu resources
  • setPriority() sets thread priority

10. How to check and solve memory leaks

Concept: Some objects have only a limited life cycle. When their tasks are completed, they will be garbage collected. If the object's life cycle is supposed to end, the object is still referenced by a series, which will cause memory leaks. .

Solution: Use the open source framework LeakCanary to detect targeted solutions.

Common memory leaks are:

  • Memory leakage caused by a singleton, for example, the Context life cycle in a singleton is greater than the Context life cycle itself;
  • The thread uses the memory shackle caused by Hander, when the activity has ended, the thread is still running to update the UI;
  • The use of static variables in non-static classes results in the inability to recover and release, resulting in leakage;
  • Too many WebView pages cause memory leaks;
  • Resources are not closed causing leakage, such as closing the connection after the database is used up.

11. View distribution mechanism, sliding conflict

There are three important methods in the event delivery sequence of View, whether dispatchTouchEvent() consumes this event, whether onInterceptTouchEvent() intercepts this event, whether onTouchEvent() handles this event, sliding conflicts are divided into sliding conflicts in the same direction, For example, ScrollView and ListView, sliding in the same direction conflict, you can calculate the height of the ListView and dynamically set the height of the ListView, and the height of the ScrollView is variable. For example, ViewPager and ListView have conflicts of sliding in different directions. One is horizontal sliding and the other is vertical sliding. Sliding in different directions can determine whether the sliding x, y axis is horizontal or vertical. If it is judged to be horizontal sliding, it will intercept ListView events. , Vertical is the opposite.

12. The difference between RecyclerView and ListView

Caching: The former caches View+ViewHolder+flag, without calling findViewById every time, the latter just caches the View.

In terms of refreshing data, the former provides partial refresh, and the latter refreshes all.

13.How to solve the recyclerView nested lag solution

Set the number of preloads:
LinearLayoutManager.setInitialPrefetchItemCount(4), the default is 2 preloads,
set the child item cache,
set the built-in sliding conflict resolution property rv.setHasFixedSize(true); rv.setNestedScrollingEnabled(false);
can be solved perfectly, However, Google does not recommend the nested use of RecyClerView. You need to find a third-party control similar to ExpandableListView to solve it.

14. Talk about MVC, MVP, MVVM

MVC: View can directly access Model! Therefore, the View will contain Model information, and some business logic will inevitably be included. In the MVC model, more attention is paid to the unchanged Model, and there are multiple different displays of the Model and View at the same time. Therefore, in the MVC model, Model does not depend on View, but View depends on Model. Not only that, because some business logic is implemented in View, it is difficult to change View, at least those business logic cannot be reused.

MVP: MVP evolved from the classic pattern MVC. Their basic ideas have similarities: Controller/Presenter is responsible for logic processing, Model provides data, and View is responsible for display. As a new model, MVP and MVC have a major difference: View does not directly use Model in MVP, the communication between them is carried out through Presenter (Controller in MVC), and all interactions occur in Inside the Presenter, and in MVC, View will read data from the direct Model instead of through the Controller.

MVVM: Two-way data binding, data-driven UI, M provides data, V view, VM is the data-driven layer

15.dagger2

Dagger2 is a framework mainly used for dependency injection, which reduces initialization object operations and reduces coupling.

16Android performance optimization

Layout optimization: reduce the layout level, use ViewStub to increase the display speed, layout, use warp_content as little as possible, delete useless attributes in the space, avoid excessive drawing, remove the default background of the window, display the booth map on demand, customize View optimization, use canvas.clipRect() identifies the visible area.

Startup speed: use distributed loading, asynchronous loading, delayed loading to improve application initialization speed, use threads to initialize data, etc., a reasonable refresh mechanism.

Memory aspect: To prevent memory leaks, use some third-party tools to detect and solve.

Code optimization: follow the Java life cycle

Installation package optimization: delete useless resources, optimize pictures, code obfuscation, avoid duplicate inventory, plug-in

17.Hander principle

Handler, loop polling detection sends messages to MessagerQuery, MessageQuery enqueues Message, Handler callback method processes the message, and overrides the handMessage method to refresh the UI.

18. What happens if SharedPreference is used across processes? How to ensure the safety of cross-process use?

Use the same shartdUserId attribute in the manifest configuration of the two applications. Application A saves data normally, and application B uses createPackageContext("com.netease.nim.demo", CONTEXT_IGNORE_SECURITY) to obtain context and then application data. To ensure data security, encryption is used storage.

19. How to improve the push arrival rate

Judging the mobile phone system, Xiaomi uses Xiaomi push, Huawei uses Huawei push, and other phones use Umeng push.

20. Activity, Fragment value passing problem

Pass value through Bundle, define variable pass value in activty, expand fragment to create pass value

21. The difference between activity and fragment

Life cycle:

The entire life cycle of fragment from creation to destruction is as follows:

onAttach()→onCreate()→onCreateView()→onActivityCreated()→onStart()→onResume()→onPause()→onStop()→onDestroyView()→onDestroy()→onDetach()

There are different methods from activity

  • onAttach(): Called when Fragment and Activity are associated;
  • onCreateView(): Called when Fragment creates a view;
  • onActivityCreated: Called after the Activity associated with the Fragment completes onCreate();
  • onDestoryView(): called when the layout in the Fragment is removed;
  • onDetach(): Called when Fragment and Activity are disassociated; Activity commonly used life cycles are only the following;
  • onCreate(): Indicates that the Activity is being created and is often used to initialize the work, such as calling setContentView to load interface layout resources, and initializing the data required by the Activity;
  • onRestart(): indicates that the Activity is restarting. Generally, when the current Acitivty changes from invisible to visible again, OnRestart will be called;
  • onStart(): Indicates that the Activity is being started. At this time, the Activity is visible but not in the foreground. It is still in the background and cannot interact with the user;
  • onResume(): Indicates that the Activity has the focus. At this time, the Activity is visible and in the foreground and starts the activity. This is the difference from onStart;
  • onPause(): Indicates that the Activity is stopping. At this time, you can do some work such as storing data and stopping animation, but it should not be too time-consuming, because this will affect the display of the new Activity. OnPause must be executed first, and the onResume of the new Activity will be carried out;
  • onStop(): Indicates that the Activity is about to stop, and you can do some heavyweight recycling work, such as logging off the broadcast receiver, closing the network connection, etc., and it should not be too time-consuming;
  • onDestroy(): Indicates that the Activity is about to be destroyed. This is the last callback in the life cycle of the Activity, which often does recycling work and resource release;

the difference:

  • Fragment has four more callback cycles than Activity, and the control operation is more flexible;
  • Fragment can be written directly in the xml file or added dynamically in Activity;
  • Fragment can use show()/hide() or replace() to switch Fragment, there will be no obvious effect when switching, and there will be obvious page turning or other effects when Activity switching;

22. What is the difference between add and replace in Fragment?

  • Add will not reinitialize fragment, replace will be every time;
  • When adding the same fragment, there will be no change in replace, and add will report IllegalStateException;
  • Replace first removes all fragments with the same id, and then adds the current fragment, and add overwrites the previous fragment. So if you use add, it will usually be accompanied by hide() and show() to avoid overlapping layouts;
  • Using add, if the application is placed in the background or destroyed by the system in other ways, when it is reopened, the fragment referenced in hide() will be destroyed, so there will still be a layout overlap bug. You can use replace or add a tag when using add parameter;

23. What are the differences and usage scenarios between FragmentPagerAdapter and FragmentStatePagerAdapter?

Each Fragment of FragmentPagerAdapter will be persistently stored in FragmentManager, as long as the user can return to the page, it will not be destroyed. Therefore, it is suitable for pages with relatively static data and a relatively small number of Fragments; FragmentStatePagerAdapter only retains the current page, and when the page is invisible, the Fragment will be eliminated and its resources released. Therefore, it is suitable for those situations where the data is more dynamic, occupies more memory, and has more fragments;

24. What are the four startup modes and application scenarios of Activity?

  • standard standard mode: every time you start an Activity, a new instance will be recreated, regardless of whether the instance already exists, the activity in this mode will enter the task stack of the Activity that started it by default;
  • singleTop stack top reuse mode: If the new Activity is already at the top of the task stack, then this Activity will not be recreated, and the onNewIntent method will be called back. If the new Activity instance already exists but is not on the top of the stack, then the Activity will still be recreated create;
  • SingleTask in-stack reuse mode: As long as the Activity exists in a task stack, the instance will not be recreated if the Activity is started multiple times, and the onNewIntent method will be called back. This mode starts Activity A, and the system first looks for whether there is what A wants Task stack, if it does not exist, it will recreate a task stack, and then put the created instance of A on the stack;
  • singleInstance single instance mode: This is an enhanced singleTask mode. An Activity with this mode can only be located in a single task stack, and there is only one instance in this task stack;

25. Talk about the relationship between Activity and window and view?

When Activity is created, a Window is initialized by attach(), which is PhoneWindow. A PhoneWindow holds an instance of DecorView. DecorView itself is a FrameLayout and inherits from View. Activty continuously adds xml layout controls to View through setContentView. Finally displayed to Window to interact with us;

26. Activity life cycle changes when switching between horizontal and vertical screens?

When the activity's android:configChanges is not set, the current Activity will be destroyed when the screen is cut, and then each life cycle will be reloaded. It will be executed once when the horizontal screen is switched, and twice when the vertical screen is switched;

onPause()→onStop()→onDestory()→onCreate()→onStart()→onResume()

Set the android:configChanges=" orientation" of Activity, tested by model

In Android5.1, that is, API 3 23 level, each life cycle will be called again when the screen is cut, and it will only be executed once when the screen is cut horizontally or vertically.

In Android9 that is API 8 28 level, the screen cut will not re-call each life cycle, only the onConfigurationChanged method will be executed

After the official correction, the original words are as follows

If your app targets Android 2 3.2, it means API level 3 13 or
higher (according to minSdkVersion and targetSdkVersion)

To be continued...

System review route before the interview

Sometimes, choice is more important than effort, and opportunity is more important than struggle. However, opportunities are only reserved for those who are prepared. Only when we are always prepared can we seize the opportunity when it comes.

Here to share with you my interview review route , friends in need can refer to:

1. Watch the video for systematic learning

The experience of Crud in the past few years has made me realize that I am really a fighter in the rookie. It is also because of Crud that my technology is relatively fragmented and not deep enough to be systematic, so it is necessary to study again. What I lack is system knowledge, poor structural framework and ideas, so learning through videos is better and more comprehensive. Regarding video learning, individuals can recommend to study at station B. There are many learning videos on station B. The only drawback is that they are free and easily outdated.

2. To systematically sort out knowledge and improve reserves

There are so many knowledge points in client development, and there are still so little things in the interview. Therefore, there are no other tricks for the interview, just to see how well you prepare for these knowledge points. So, when you go out for an interview, it is good to see which stage you have reached in your review.

System learning direction:

  • Essential skills for architects: in-depth Java generics + annotations in simple language + concurrent programming + data transmission and serialization + Java virtual machine principle + reflection and class loading + dynamic proxy + efficient IO

  • Android advanced UI and FrameWork source code: advanced UI promotion + Framework kernel analysis + Android component kernel + data persistence

  • 360° overall performance tuning: design ideas and code quality optimization + program performance optimization + development efficiency optimization

  • Interpretation of open source framework design ideas: hot repair design + plug-in framework interpretation + component framework design + image loading framework + network access framework design + RXJava responsive programming framework design + IOC architecture design + Android architecture component Jetpack

  • NDK module development: NDK basic knowledge system + underlying image processing + audio and video development

  • WeChat Mini Program: Mini Program Introduction + UI Development + API Operation + WeChat Docking

  • Hybrid development and Flutter: Html5 project combat + Flutter advanced

After the knowledge is sorted out, it is necessary to check and fill in the vacancies. Therefore, for these knowledge points, I have prepared a lot of e-books and notes on hand. These notes provide a perfect summary of each knowledge point.

3. Read the source code, read the actual combat notes, and learn the ideas of God

"Programming language is the way the programmer expresses, and the architecture is the programmer's perception of the world." Therefore, if programmers want to quickly understand and learn the architecture, reading the source code is essential. Reading the source code is to solve problems + understand things, and more importantly: see the ideas behind the source code; programmers say: read thousands of lines of source code, and practice thousands of ways.

4. On the eve of the interview, sprint questions

Within a week before the interview, you can start sprinting. Please keep in mind that when brushing the questions, the technology is the first priority, and the algorithm is basic, such as sorting, etc., and the intellectual questions are generally not asked unless they are school recruits.

Regarding the interview questions, I personally prepared a set of systematic interview questions to help you learn from one another:

The above content is free to share with everyone, friends who need the full version, click here to see all the content .

Guess you like

Origin blog.csdn.net/weixin_44339238/article/details/112853749