Skip to content
matboniface edited this page Oct 22, 2012 · 7 revisions

Since AndroidAnnotations 2.7

This annotation is intended to be used on a method to receive results from a previously started activity using android.app.Activity.startActivityForResult(Intent, int)

The annotation value must be a resource id that represents the requestCode associated with the given result. This id can be declared into xml values as follows : <item type="id" name="myRequest"/>

The method may have multiple parameters :

  • A android.content.Intent that contains data returned by the previously launched activity
  • An int or an java.lang.Integer to get the resultCode.

Some usage examples of @OnActivityResult annotation :

 @OnActivityResult(R.id.myRequest)
 void onResult(int resultCode, Intent data) {
 	// Use resultCode and data
 }
 
 @OnActivityResult(R.id.myRequest)
 void onResult(int resultCode) {
 	// Only use resultCode 
 }
 
 @OnActivityResult(R.id.myRequest)
 void onResult(Intent data) {
 	// Only use data
 }
 
 @OnActivityResult
 void myRequestResult() {
 	// The method name contains the res id
 }
 
 @OnActivityResult(resName = "myRequest")
 void anotherResult() {
 	// Usually for library projects
 }

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally