Dec 4, 2012

Android Annotation

What is Annotation ?
Annotation in Programming Language ?
History of Annotation in Java ?
Use of Annotation ?
Can I use Java’s Annotation in Android ?
Is there any Annotation framework available for Android ?


What is Annotation ?
“An annotation is a note that is made while reading any form of text.” Standard definition of Annotation.

Annotation in Programming Language ?
“Initially annotation was mainly use to extend documents and comments, Annotation was ignored in compile and execution process, Today annotation is greatly improved in language like Java, C#,etc. Many functionality and frameworks are build upon annotation. Annotations offer a way to associate metadata with program elements i.e. classes, interfaces, and methods. They can be thought of as additional modifiers without changing the generated code for those elements.” - Annotation in Programming Language

History of Annotation in Java ?

In Java annotation was introduction as JSR-175 in 2002 as named Metadata Facilities of Java Programming language, It was approved in 2004 by JCP. Till this date annotation was ignored by compiler and used to build javadoc, now it is not possible to ignore annotation so that JSR-269 was submitted in 2005 to make provision to process annotation at compile time. JSR-269 was  approved in 2006 after that Annotation was official part of Java language and shipped with JDK 1.5

Use of Annotation ?

  • Generate API Document - Annotation can be use in documentation.
  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compiler-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime, few frameworks are based on Annotation, Servlet 3.0 for configuration.

Can I use Java’s Annotation in Android ?
Only few basic annotation like @Override can be used in newer version.

Is there any Annotation framework available for Android ?
Yes, Android Annotation [ http://androidannotations.org/ ] is good framework.

Android Annotation

It is good annotation library which allow you to manage and maintain all Android specific objects with annotation.

Referring UI Element Example

// without annotation

Button btn = (Button) findViewById(R.id.mybutton);
// with annotation
@ViewId
Button btn;


Features

  • Dependency injection: inject views, extras, system services, resources, ...
  • Simplified threading model: annotate your methods so that they execute on the UI thread or on a background thread.
  • Event binding: annotate methods to handle events on views, no more ugly anonymous listener classes!
  • REST client: create a client interface, AndroidAnnotations generates the implementation.
  • AndroidAnnotations provide those good things and even more for less than 50kb, without any runtime perf impact!

To Learn AndroidAnnotation Visit following links