public class WebAuthProvider { private static WebAuthProvider providerInstance; private WebAuthProvider(@NonNull Auth0 account) { this.account = account; //Set default values } public static class Builder { //private constructor. Can only be instantiated from the init() method. Builder(Auth0 account) { this.account = account; } //Builder methods to configure the instance //... /// /** * Begins the authentication flow. */ public void start(@NonNull Activity activity, @NonNull AuthCallback callback, int requestCode) { providerInstance = new WebAuthProvider(account) .useBrowser(useBrowser) .useFullscreen(useFullscreen) .withState(state) .withScope(scope) .useCodeGrant(useCodeGrant) .withParameters(parameters) .withConnection(connectionName); providerInstance.start(activity, callback, requestCode); } } // Public methods (User interface) // Inits the instance. Can be configured, the user will finally call start(). public static Builder init(@NonNull Auth0 account) { return new Builder(account); } //Finish the authentication if an instance is found public static boolean resume(int requestCode, int resultCode, Intent data) { if (providerInstance == null) { Log.w(TAG, "There is no previous instance of this provider."); return false; } return providerInstance.authorize(requestCode, resultCode, data); } public static boolean resume(Intent data) { if (providerInstance == null) { Log.w(TAG, "There is no previous instance of this provider."); return false; } return providerInstance.authorize(data); } // End Public methods // Private methods to handle the authentication //... }