Android development sdk! This is a review guide for Android developers, advanced learning materials!

Preface

Mobile R&D is hot, and more and more people are starting to learn android development. However, many people feel that it is easy to get started and it is difficult to grow up. They are rather confused about the future. They don't know how to improve their skills and what needs to be added to the next stage. The market is also mostly talking about knowledge graphs, lacking a system and a sense of growth rhythm. I hereby compile an advanced road to android R&D, I hope it can be helpful to everyone.

Here I divide the siege lion into four stages: elementary, intermediate, advanced, and senior, and make requirements for R&D and design capabilities, tool use, system principles, and architecture.

ByteDance has asked this question on three sides. I have sorted it out here. I hope it can help everyone. Welcome to check and fill in the vacancies.

Separation of data processing and view loading

We know that pulling data from the remote must be asynchronous. After we pull the data, we may hurriedly throw the data to the VH for processing. In fact, we should also place the data processing logic in asynchronous processing, so After the Adapter notify the change, ViewHolder can do data and view binding logic simply and without pressure, such as:

mTextView.setText(Html.fromHtml(data).toString())

The Html.fromHtml(data) method here may be more time-consuming. If there are multiple TextViews, the time-consuming will be more serious, which will cause frame drops and freezes. If you put this step together with the network asynchronous thread From the user's point of view, the network refresh time is a little longer at most.

Data optimization

Pull remote data by paging, cache the pulled remote data, improve the speed of secondary loading; for newly added or deleted data, use DiffUtil to refresh the data locally instead of blindly refreshing the data globally.

Layout optimization

Reduce transition drawing

To reduce the layout level, you can consider using a custom View to reduce the level, or set the layout more reasonably to reduce the level. It is not recommended to use ConstraintLayout in RecyclerView. Many developers have already reported that using it is even worse. Related links are: Is ConstraintLayout that slow?, constraintlayout 1.1.1 not work well in listview.

Reduce xml file inflate time

The xml file here includes not only the xml of the layout, but also the xml of the drawable. The xml file inflate out the ItemView through time-consuming IO operations, especially when the probability of Item reuse is very low, as the Type increases, this The loss caused by inflate is quite large. At this time, we can use code to generate the layout, that is, the new View() method, as long as we figure out the API corresponding to the attributes of each node in the xml.

Reduce the creation of View objects

A slightly complex Item will contain a large number of Views, and the creation of a large number of Views will also consume a lot of time, so the ItemView should be simplified as much as possible; when designing the ItemType, design the part that can be shared by multiple ViewTypes as much as possible to design a custom View to reduce the View The construction and nesting.

other

Others do not mean that they are not important, but I can't classify them. Some operations may greatly optimize your RecyclerView.

  • Upgrade RecycleView version to 25.1.0 and above to use Prefetch function, please refer to RecyclerView data prefetching.
  • If the Item height is fixed, you can use RecyclerView.setHasFixedSize(true); to avoid requestLayout wasting resources;
  • Set RecyclerView.addOnScrollListener(listener); to stop the loading operation during the sliding process.
  • If animation is not required, you can pass ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false); turn off the default animation to improve efficiency.
  • Use String.toUpperCase for TextView instead of android:textAllCaps="true".
  • Use custom View of StaticLayout or DynamicLayout for TextView instead of it.
  • Recycle resources by overriding RecyclerView.onViewRecycled(holder).
  • Use RecycleView.setItemViewCacheSize(size); to increase the cache of RecyclerView, and use space for time to improve the smoothness of scrolling.
  • If the Adapter of multiple RecycledViews is the same, for example, the same Adapter exists in the nested RecyclerView, you can share a RecycledViewPool by setting RecyclerView.setRecycledViewPool(pool);.
  • Set up a listener for ItemView. Don't call addXxListener for each Item. You should share an XxListener and perform different operations based on the ID, which optimizes the resource consumption caused by frequent creation of objects.
  • Use getExtraLayoutSpace to increase the extra space reserved by RecyclerView (outside the display range, there should be extra cache space), as shown below:
new LinearLayoutManager(this) { 
@Override protected int getExtraLayoutSpace(RecyclerView.State state) {
 return size; 
} 
};

At last

Taking into account the length of the article, I made these questions and answers, as well as the questions I encountered in many years of interviews, and some interview materials into PDF documents. If you need a friend, you can privately mail me [Interview] to receive it for free

Click here to receive a summary of Android interview materials

mg-lbxroUhK-1614050724720)]

[External link image is being transferred...(img-jHECy98f-1614050724723)]

Friends who like it can follow, forward, and like thank you!

Guess you like

Origin blog.csdn.net/a120464/article/details/113978447