dependencies {
  compile 'com.vanniktech:onactivityresult:0.7.0'
  annotationProcessor 'com.vanniktech:onactivityresult-compiler:0.7.0'


compile 'com.vanniktech:onactivityresult:0.8.0-SNAPSHOT'
annotationProcessor 'com.vanniktech:onactivityresult-compiler:0.8.0-SNAPSHOT'

Modules are located on Maven Central.


Override onActivityResult in your Activity / Fragment and call ActivityResult.onResult

protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  ActivityResult.onResult(requestCode, resultCode, data).into(this);

Annotate your methods and get the callback

@OnActivityResult(requestCode = 33)
void onActivityResultTestActivity() { /* Do something */ }

@OnActivityResult(requestCode = 1, resultCodes = { Activity.RESULT_OK })
void onActivityResultActivityOk() { /* Only do something when ok */ }

@OnActivityResult(requestCode = 1, resultCodes = { Activity.RESULT_CANCELED })
void onActivityResultActivityCanceled() { /* Only do something when canceled */ }

@OnActivityResult(requestCode = 2)
void onActivityResultPickImage(final int resultCode, final Intent intent) { /* Do something */ }

Various parameters are supported:

Where int parameters will get the resultCode and Intent parameters will get the Intent.

Note: Each annotated method shall only have one int and / or Intent variable.

In addition to that other parameter annotations are supported like:

Some examples can be found here.

The @Extra annotation is generic and works with every type mentioned above. In addition it also supports custom types which are implementing Parcelable or Serializable.

The disadvantage of @Extra is that it won't let you specify a default value therefore the other annotations do exist and should be used when needed.

Advantages over AfterMath


Thanks to JakeWharton's ButterKnife

Thanks to Hannes Dorfmann's Annotation Processing 101


Copyright (C) 2015 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0