当前位置:网站首页>Common optimization items
Common optimization items
2022-06-29 04:41:00 【Forgetful fish】
Optimize
Handwriting , Write where you want , Irregular change
Glide
- Use
simpleTagAnd so oninto()Object time , Need to set upoverride()Property to avoid loading images that are too largeOOM - For a fixed area, display a large image , If the display can be intercepted, the intercepted part can be displayed in the control , Use
Bitmap.createBitmap(scaleBitmap, 0, 0, w, h)Tailoring - Available for large drawings BitmapRegionDecoder Perform a regional display , Refer to the large picture to show demo
onDestroy Delay the
- because onstop And onDestroy The execution is in the main thread IdleHandle Execute under callback , If the main thread has unfinished tasks , You cannot immediately call back onstop And onDestroy, but onReume Will be delayed 10s Then call the exit method as a strategy to reveal the details
- Solution 1 : Find the blocked thread , Generally, it is caused by the fact that the animation does not stop logging off when jumping or closing the page, or some monitoring is not cancelled
- Solution 2 : If the cause of the blockage is difficult to find , Can be in onPause Judge isFinish() To decide whether to recycle resources , Execute the code to be recycled in advance , Simple and effective , The possible hidden trouble lies in onStop,onDestroy The object in is recycled in advance, resulting in a null pointer , And that is getLifecycle().addObserver() The rhythm of bound object life cycle execution is inconsistent
- Reference resources Check what the main thread does
Resource pictures
- Try to add multi-resolution pictures , Otherwise, it may cause the picture to occupy too much memory on the HD device
- Use imageAsset To make the ic_launcher The picture is covered with a transparent layer , You may not get the desired shape when you crop the display , Use other png Pictures can be substituted
- Updating the progress bar during file download may cause the interface to change because of too frequent callback ddos, It can be done by handle Controls the minimum granularity of the refresh
WebView Optimize
1. In the use of WebView In more frequent projects , A can be initialized in advance WebView To be used , Direct reference when required ,app Destroy on exit , For details, please refer to H5 Realize second on
2. The destruction WebView
@Override
protected void onDestroy() {
super.onDestroy();
// First remove... From the parent control WebView
mWebViewContainer.removeView(mWebView);
mWebView.stopLoading();
mWebView.getSettings().setJavaScriptEnabled(false);
mWebView.clearHistory();
mWebView.removeAllViews();
mWebView.destroy();
}
RecyclerView
1.NestScrollView And RecyclerView Nesting can lead to recycler It can't be reused , Cause sliding jamming
Sliding nested processing
2. Paging query causes duplicate data resolution due to new data The main idea is to get in and out of the last ID To the backstage , The background always takes the first page when taking values , At the same time, compare ID Size confirms the page data , Avoid inaccurate data caused by deletion or insertion
Dialog
- dialog Used in editText No cursor display is used
android:textCursorDrawable="@drawable/my_cursor"Property to set
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/green" />
<size android:width="1dp" />
</shape>
Commonly used list choice
- ArrayMap
ArrayMap The use of HashMap It's the same . When the data structure is <key,value> When , You can use ArrayMap replace .
But compared to HashMap,ArrayMap stay Android Is not always efficient . When the amount of data is large ( Hundreds of ) after , Its performance will degrade at least 50%. therefore , When the amount of data is small , Use ArrayMap The efficiency is quite high
- SparseArray
Also with a <Key,Value> Yes
SparseIntArray: When map The structure of is Map<Integer,Integer> When you use , More efficient .
SparseBooleanArray: When map The structure of is Map<Integer,Boolean> When you use , More efficient .
SparseLongArray: When map The structure of is Map<Integer,Long> When you use , More efficient .
LongSparseArray: When map The structure of is Map<Long,Value> When you use , More efficient .
- ArraySet
and ArrayMap For a similar purpose , To improve HashSet The efficiency of . How to use it HashSet similar
- String And list< String > Fast inter rotation Need to import .guava tool kit
compile 'com.google.guava:guava:26.0-jre'
list->String : String s=Joiner.on(",").join(list);
String->list: List< String > listSplitter.on("-").splitToList(str)
String
- Display with % Characters may be reported UnknownFormatConversionException,% Need to escape %%
边栏推荐
猜你喜欢
随机推荐
Decorator Pattern
1019 数字黑洞
LabVIEW显示Unicode字符
什么是匿名内部类,如何使用匿名内部类
It is said on the Internet that a student from Guangdong has been admitted to Peking University for three times and earned a total of 2million yuan in three years
[Verilog quick start of Niuke network question brushing series] ~ asynchronous reset Series T trigger
Technical parameters of Tektronix DPO4104 digital fluorescence oscilloscope
Remediation for Unsafe Cryptographic Encryption
Flyweight pattern
【HackTheBox】dancing(SMB)
从零到一,教你搭建「以文搜图」搜索服务(一)
Live broadcast appointment AWS data everywhere series activities
How to create a subtype like relationship between two generic classes when the classes are generic related
Research Report on the overall scale, major manufacturers, major regions, product and application segmentation of disposable hearing aid batteries in the global market in 2022
Cucumber test practice
What are the basic usage methods of MySQL
Research Report on the overall scale, major manufacturers, major regions, products and applications of high temperature film capacitors in the global market in 2022
Mysql 中的 mvcc原理
Experience sharing of system analysts in preparing for exams: phased and focused
be based on. NETCORE development blog project starblog - (13) add friendship link function









