Introduction:
Android Support Annotations is an annotation library introduced from version 19.1, which can optimize code, increase readability, and reduce code error reporting
Use:
1: boot pack
implementation 'com.android.support:support-annotations:23.4.0'
2:Support Annotations classification
2.1:Nullness annotation
@Nullable annotation can be used to identify specific parameters or return value can be null
@The NonNull annotation can be used to identify that the parameter cannot be null
2.2:Resource Type annotation
2.3:Threading notes
Threading comment:
@UiThread UI thread
@MainThread
@Worker thread
@BinderThread binding thread
2.4:Value Constraints comments: @ Size, @IntRange, @FloatRange
2.5:Permissions note: @ RequiresPermission
@RequiresPermission(Manifest.permission.SET_WALLPAPER)
public abstract void setWallpaper(Bitmap bitmap) throws IOException;
//If you need at least one of the permission sets, you can use the anyOf property
@RequiresPermission(anyOf = {
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION})
public abstract Location getLastKnownLocation(String provider);
//If you need multiple permissions at the same time, you can use the allow attribute
@RequiresPermission(allOf = {
Manifest.permission.READ_HISTORY_BOOKMARKS,
Manifest.permission.WRITE_HISTORY_BOOKMARKS})
public static final void updateVisitedHistory(ContentResolver cr, String url, boolean real) ;
//For the permissions of intents, you can directly mark the permission requirements on the defined intent constant string fields (they are usually already @ SdkConstant
//Note marked)
@RequiresPermission(android.Manifest.permission.BLUETOOTH)
public static final String ACTION_REQUEST_DISCOVERABLE =
"android.bluetooth.adapter.action.REQUEST_DISCOVERABLE";
//For the permission of content providers, you may need to mark the Read and Write permission access separately, so you can mark @ Read or @ Write
//Every permission requirement
@RequiresPermission.Read(@RequiresPermission(READ_HISTORY_BOOKMARKS))
@RequiresPermission.Write(@RequiresPermission(WRITE_HISTORY_BOOKMARKS))
public static final Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");
If the project has requirements, it can be widely used