AutoResolveHelper

  • AutoResolveHelper is a helper class to resolve Tasks that may require showing UI before returning a result.

  • By callingresolveTask, the helper will handle necessary UI and return the result to your activity'sonActivityResult.

  • This helper is useful for Google Play Services APIs that might need user interaction before providing results, provided the API's results implementAutoResolvableResult.

  • You can retrieve the result, a cancellation signal, or an error status within youronActivityResult method based on theresultCode.

  • TheresolveTask method is deprecated and should be replaced with contracts inTaskResultContracts.

public classAutoResolveHelper extendsObject

Helper to auto resolveTasks that may throwResolvableApiException to request UI being shown before returning the result.

By calling resolveTask(Task, Activity, int) with your task, this helper will make sure that it shows any UI if necessary and at the end will return the result back to your activity's Activity.onActivityResult(int, int, Intent).

This is useful for handling Google Play Services APIs that may have to show UI to the user before returning their results back. Note that only APIs whose results implement theAutoResolvableResult are compatible with this helper.

Below is an example of an hypotheticalloadFoo API that returns aFooResult but that may require the user to consent to sharing the resultData inFooResult the first time before returning it to you.

   public static class SampleActivity extends Activity {     private static final int REQUEST_CODE_FOO = 1234;     @Override     public onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       if (savedInstanceState == null) {         // Loading Foo         FooClient fooClient = Foo.getFooClient(...);         Task fooTask = fooClient.loadFoo();         // Asking AutoResolveHelper to take care of resolving         // any ResolvableApiExceptions, showing UI if necessary         // and just piping FooResult to onActivityResult.         AutoResolveHelper.resolveTask(fooTask, this, REQUEST_CODE_FOO);       }     }     @Override     protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {       switch (requestCode) {         case REQUEST_CODE_FOO:           if (resultCode == Activity.RESULT_OK) {             FooResult fooResult = FooResult.getFromIntent(resultData);             // Result loaded, use it ...           } else if (resultCode == Activity.RESULT_CANCELLED) {             // user cancelled ...           } else if (resultCode == AutoResolveHelper.RESULT_ERROR) {             // there was an error, handle it or ignore ...             int errorCode = AutoResolvableHelper.getStatusFromIntent(resultData);             // handle the error, log, ...           }           break;         default:           super.onActivityResult(requestCode, resultCode, resultData);       }     }   }
    Notes from the example above:
  • You will receive a response back withrequestCode matching the one you originally passed in the call to resolveTask(Task, Activity, int).
  • You will receiveresultCode equal toActivity.RESULT_OK when the call has been successful and you should be able to retrieve the actual result object from theresultData param. By convention result classes that can be used with this helper should have agetFromIntent(Intent) method that you can use to retrieve the result object.
  • You will receiveresultCode equal toActivity.RESULT_CANCELED when the user has cancelled the UI that this helper has shown.
  • You will receiveresultCode equal toRESULT_ERROR when an error occurs resolving the result of the givenTask. In that case, you may call getStatusFromIntent(Intent) passingresultData param to get theStatus with the details about the error.

Constant Summary

int RESULT_ERRORThe result code that anActivity passed to resolveTask(Task, Activity, int) will receive in case an error happened.

Public Method Summary

staticStatus
static void
putStatusIntoIntent(Intent data,Status status)
Saves the givenStatus as an extra in the givenIntent.
static <TResult extends AutoResolvableResult> void
resolveTask(Task<TResult> task,Activity activity, int requestCode)
This method is deprecated. Use one of the contracts in TaskResultContracts as a replacement for this API. These contracts conform to the new Activity Result APIs introduced in AndroidX, and lets you obtain results from tasks that require intent-based resolution.

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
finalClass<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()

Constants

public static final intRESULT_ERROR

The result code that anActivity passed to resolveTask(Task, Activity, int) will receive in case an error happened.

You can use getStatusFromIntent(Intent) to retrieve the actualStatus for the error.

Constant Value:1

Public Methods

public staticStatusgetStatusFromIntent(Intent data)

Returns theStatus from theIntent received in Activity.onActivityResult(int, int, Intent).

This method is expected to be called from Activity.onActivityResult(int, int, Intent) of activities passed to resolveTask(Task, Activity, int).

Note this method will return null ifresultCode was not set toRESULT_ERROR.

public static voidputStatusIntoIntent(Intent data,Status status)

Saves the givenStatus as an extra in the givenIntent.

The savedStatus can be read back by calling getStatusFromIntent(Intent).

public static voidresolveTask(Task<TResult> task,Activity activity, int requestCode)

This method is deprecated.
Use one of the contracts inTaskResultContracts as a replacement for this API. These contracts conform to the new Activity Result APIs introduced in AndroidX, and lets you obtain results from tasks that require intent-based resolution.

Resolves the given task result showing UI if necessary and pipes back the final result back to the givenactivity's Activity.onActivityResult(int, int, Intent) callback.

Note that this method adds aFragment to your activity, so only call this method ifFragmentManager is in a state where it can execute fragment transactions without state loss. The added fragment will be auto removed after the task result is delivered to your activity.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-01 UTC.