Beijing Institute of Deep Research Institute app Knowledge Summary:

Source: Internet
Author: User

1) app code frame setting;

MVC;
1-baseactivity and Myactivitymanager cooperate with Android's activity start mode to achieve full control of activity;
2-Encapsulating the network request layer
3-Separating the code with the MVC architecture.

The understanding of the MVC architecture is as follows (assuming that data persistence is going through a network request to server):
m layer, set the data model for the Xxx.java class, and encapsulate the acquisition and uploading of Xxxmodel.java data.
layer C, Xxcontroller.java, invokes the interface of the M-layer encapsulated data acquisition or upload, and sets the callback function to tell the V-layer to update the UI.
V-layer, Xxxactivity.java is responsible for the display of the interface, as well as calling the C-Layer business logic interface, and writing a C-level callback function.

So, the method of invocation is that v layer calls the business logic method of layer C, and write the callback function to update the UI after the business logic is complete, and then the C layer calls the M layer to execute the real business logic code.
If you want to expand, for example, to add a photo business, to process the photos, then I just need to add photomodel to the photo, and Photocontroller. As for activity, there is nothing sticky with layer c.
controller can be replaced at any time.

So why is this MVC framework gradually being phased out?
Because, the activity code will be more and more, the activity will be more and more bloated, the activity itself to display and change the interface, but also to make business logic calls.
there should be no one who wants to face an activity with 3000 rows and a complex business logic. Therefore, the activity directly calls the C-layer to change the way.
now, the C-tier is carved up. The original C layer is responsible for calling the business logic of the M layer, and also invoking activity's listener events.

MVC, in activity, does not just invoke the business logic code, but also writes the view update operation after the business is completed.
instead of invoking the business logic code directly, mvp:activity encapsulates the business logic by the P layer and the View Update operation (callback) after the business completes.
The P-tier, which is a coordinated view update and data interaction for a piece of business. In other words, the P-layer encapsulates the data interface of the current business and the operation of the interface update. Keep your activity code more organized.

2) ListView optimization;

Appearance optimization (divider line, scroll bar),
Efficiency optimization (scrolling monitoring onscroll (), Onscrollstatechange (), Touch monitoring ontouchevent (), and Viewholder mode code optimization, adapter optimization when dealing with large amounts of data)


3) Custom Controls

Their classification, and how each category is used;


4) App performance optimization


1) layout optimization
1-based on a principle, the Android drawing interface is through the view tree to traverse the drawing, if the view is too high (that is, too many levels), it will affect the speed of the drawing, so, to make the tree structure as flat as possible, not too many levels , you can use a relative layout as the root layout to flatten the layout.
2-avoid useless layout, obviously there is only one child in the layout, then this layout may be useless. Delete it.
3-use the include tag for layout reuse.
4-uses viewstub for lazy loading. (Viewstub is a magical thing that can be unfolded as a "branch", but before it unfolds it is invisible and takes up no space, and it comes with a inflate method that can be expanded before it is drawn, so if there are some hidden controls, You do not need to draw when the interface is initialized, you can use Viewstub to speed up the loading of the interface.


2) Memory optimization
Bitmap is the biggest threat that causes memory to be high or memory overflow. 1-Use the appropriate resolution and size of the picture; 2-Recycle recycle after bitmap, 3-use picture cache.
Reduce unnecessary creation of objects.
It is not necessary to use the reflection mechanism, because reflection can cause performance degradation.
Use Surfaceview instead of view to do a lot of, frequent drawing operations.
Do not call inflate frequently for view instantiation.
If there is a memory leak or overflow, you need to use the DDMS tool, grab the hprof file, analyze it with the Mat tool, find out the location of the leak, and fix it.


5) Round head


Roundedbitmapdrawable class, to set the ImageView fillet, if the picture is square, and the fillet angle is half the length of the square side, then a circular picture will be formed.
Alternatively, you can use a third-party open source project, Circleimageview.
The former can handle rounded corners flexibly, and a circular chart is only part of its function.
The latter, can achieve the rich control of the circular graph, the control of the circular graph, more powerful than the former, can have a border setting.

6) Okhttp request HTTPS;

Beijing Institute of Deep Research Institute app Knowledge Summary:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.