Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

OnActivityResult

Francis edited this page Oct 8, 2015 · 9 revisions

Since AndroidAnnotations 2.7

This annotation is intended to be used on methods to receive results from an activity started with android.app.Activity.startActivityForResult(Intent, int)

The annotation value must be an integer constant that represents the requestCode associated with the given result.

The method may have multiple parameters :

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

Some usage examples of @OnActivityResult annotation :

 @OnActivityResult(REQUEST_CODE)
 void onResult(int resultCode, Intent data) {
 }
 
 @OnActivityResult(REQUEST_CODE)
 void onResult(int resultCode) {
 }
 
 @OnActivityResult(ANOTHER_REQUEST_CODE)
 void onResult(Intent data) {
 }
 
 @OnActivityResult(ANOTHER_REQUEST_CODE)
 void onResult() {
 }

Since AndroidAnnotations 3.2

You can inject extras from the received Intent to method parameters with the @OnActivityResult.Extra annotation. This annotation can be only used on method parameters, and the related method must have the @OnActivityResult annotation. Also the type of the parameter must be addible to a Bundle. The annotation value is the key used for the result data. If not set, the field name will be used as the key.

Some usage examples of @OnActivityResult.Extra annotation :

@OnActivityResult(REQUEST_CODE)
void onResult(int resultCode, Intent data, @OnActivityResult.Extra String value) {
}

@OnActivityResult(REQUEST_CODE)
void onResult(int resultCode, @OnActivityResult.Extra(value = "key") String value) {
}

@OnActivityResult(REQUEST_CODE)
void onResult(@OnActivityResult.Extra String strVal, @OnActivityResult.Extra int intVal) {
}

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally