OnActivityResult - shiraji/androidannotations GitHub Wiki
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)](http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.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 ajava.lang.Integer
to get theresultCode
.
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) {
}