Android

Android TutorialAdding a FuseView to an Android ProjectAndroid 9-Patch ImagesAndroid Accessing SQLite databases using the ContentValues classAndroid Accounts and AccountManagerAndroid ACRAAndroid ActivityAndroid Activity RecognitionAndroid adb (Android Debug Bridge)Android adb shellAndroid AdMobAndroid AIDLAndroid AlarmManagerAndroid Android-x86 in VirtualBoxAndroid Animated AlertDialog BoxAndroid AnimatorsAndroid Annotation ProcessorAndroid Architecture ComponentsAndroid AsyncTaskAndroid AudioManagerAndroid AudioTrackAndroid AuthenticatorAndroid AutoCompleteTextViewAndroid Autosizing TextViewsAndroid Barcode and QR code readingAndroid Bitmap CacheAndroid Bluetooth and Bluetooth LE APIAndroid Bluetooth Low EnergyAndroid Bottom SheetsAndroid BottomNavigationViewAndroid BroadcastReceiverAndroid Building Backwards Compatible AppsAndroid ButterKnifeAndroid ButtonAndroid Callback URLAndroid Camera 2 APIAndroid Camera and GalleryAndroid Canvas drawing using SurfaceViewAndroid Capturing ScreenshotsAndroid CardViewAndroid Check Data ConnectionAndroid Check Internet ConnectivityAndroid CleverTapAndroid ColorsAndroid ConstraintLayoutAndroid ConstraintSetAndroid ContentProviderAndroid ContextAndroid CoordinatorLayout and BehaviorsAndroid Count Down TimerAndroid Crash Reporting ToolsAndroid Create Singleton Class for Toast MessageAndroid Creating Custom ViewsAndroid Creating Overlay (always-on-top) WindowsAndroid Creating Splash screenAndroid Custom FontsAndroid Dagger 2Android Data Binding LibraryAndroid Data Encryption/DecryptionAndroid Data Synchronization with Sync AdapterAndroid Date and Time PickersAndroid DayNight Theme (AppCompat v23.2 / API 14+)Android Define step value (increment) for custom RangeSeekBarAndroid Design PatternsAndroid Device Display MetricsAndroid DialogAndroid Displaying Google AdsAndroid Doze ModeAndroid DrawablesAndroid EditTextAndroid Email ValidationAndroid EmulatorAndroid Enhancing Alert DialogsAndroid ExceptionsAndroid ExoPlayerAndroid FastjsonAndroid fastlaneAndroid FileProviderAndroid FirebaseAndroid Firebase App IndexingAndroid Firebase Cloud MessagingAndroid Firebase Crash ReportingAndroid Firebase Realtime DataBaseAndroid FloatingActionButtonAndroid Formatting phone numbers with pattern.Android Formatting StringsAndroid FragmentsAndroid FrescoAndroid game developmentAndroid Gesture Detection



Android Annotation Processor

From WikiOD

Annotation processor is a tool build in javac for scanning and processing annotations at compile time.

Annotations are a class of metadata that can be associated with classes, methods, fields, and even other annotations.There are two ways to access these annotations at runtime via reflection and at compile time via annotation processors.

@NonNull Annotation[edit | edit source]

public class Foo {
    private String name;
    public Foo(@NonNull String name){...};
    ...
}

Here @NonNull is annotation which is processed compile time by the android studio to warn you that the particular function needs non null parameter.

Types of Annotations[edit | edit source]

There are three types of annotations.

Marker Annotation - annotation that has no method

@interface CustomAnnotation {}

Single*Value Annotation - annotation that has one method

@interface CustomAnnotation {  
    int value();  
}

Multi*Value Annotation - annotation that has more than one method

@interface CustomAnnotation{  
    int value1();  
    String value2();  
    String value3();  
}

Creating and Using Custom Annotations[edit | edit source]

For creating custom annotations we need to decide

  • Target - on which these annotations will work on like field level, method level, type level etc.
  • Retention - to what level annotation will be available.

For this, we have built in custom annotations. Check out these mostly used ones:

@Target

Target and what it means

@Retention

Retention and what it means

Creating Custom Annotation

@Retention(RetentionPolicy.SOURCE) // will not be available in compiled class   
@Target(ElementType.METHOD) // can be applied to methods only
@interface CustomAnnotation{  
      int value();    
}

Using Custom Annotation

class Foo{  
  @CustomAnnotation(value = 1)  // will be used by an annotation processor
  public void foo(){..}  
}

the value provided inside @CustomAnnotation will be consumed by an Annotationprocessor may be to generate code at compile time etc.

Credit:Stack_Overflow_Documentation