Source:
<code>protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fui_activity_register_phone); final PhoneProviderResponseHandler handler = ViewModelProviders.of(this).get(PhoneProviderResponseHandler.class); <START> handler.init(getFlowParams()); <END> handler.getOperation().observe(this, new ResourceObserver<IdpResponse>( this, R.string.fui_progress_dialog_signing_in) { @Override protected void onSuccess(@NonNull IdpResponse response) { startSaveCredentials(handler.getCurrentUser(), response, null); } @Override protected void onFailure(@NonNull Exception e) { handleError(e); } }); final PhoneNumberVerificationHandler verificationHandler = ViewModelProviders.of(this).get(PhoneNumberVerificationHandler.class); verificationHandler.init(getFlowParams()); verificationHandler.getOperation().observe(this, new ResourceObserver<PhoneAuthCredential>( this, R.string.fui_verifying) { @Override protected void onSuccess(@NonNull PhoneAuthCredential credential) { handler.startSignIn(credential, new IdpResponse.Builder( new User.Builder(PhoneAuthProvider.PROVIDER_ID, null) .setPhoneNumber(getPhoneNumber()) .build()) .build()); } @Override protected void onFailure(@NonNull Exception e) { if (e instanceof PhoneNumberVerificationRequiredException) { if (getSupportFragmentManager() .findFragmentByTag(SubmitConfirmationCodeFragment.TAG) == null) { showSubmitCodeFragment( ((PhoneNumberVerificationRequiredException) e).getPhoneNumber()); } handleError(null); } else { handleError(e); } } }); if (savedInstanceState != null) { return; } Bundle params = getIntent().getExtras().getBundle(ExtraConstants.PARAMS); CheckPhoneNumberFragment fragment = CheckPhoneNumberFragment.newInstance(params); getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_phone, fragment, CheckPhoneNumberFragment.TAG) .disallowAddToBackStack() .commit(); }</code><technical_language>nit: name this more specific handler? of verificationHandler a bit confusing</technical_language>

Target:
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fui_activity_register_phone); final PhoneProviderResponseHandler handler = ViewModelProviders.of(this).get(PhoneProviderResponseHandler.class); handler.init(getFlowParams()); handler.getOperation().observe(this, new ResourceObserver<IdpResponse>( this, R.string.fui_progress_dialog_signing_in) { @Override protected void onSuccess(@NonNull IdpResponse response) { startSaveCredentials(handler.getCurrentUser(), response, null); } @Override protected void onFailure(@NonNull Exception e) { handleError(e); } }); final PhoneNumberVerificationHandler phoneVerifier = ViewModelProviders.of(this).get(PhoneNumberVerificationHandler.class); phoneVerifier.init(getFlowParams()); phoneVerifier.getOperation().observe(this, new ResourceObserver<PhoneVerification>( this, R.string.fui_verifying) { @Override protected void onSuccess(@NonNull PhoneVerification verification) { if (verification.isAutoVerified()) { Toast.makeText( PhoneActivity.this, R.string.fui_verified, Toast.LENGTH_LONG).show(); } handler.startSignIn(verification.getCredential(), new IdpResponse.Builder( new User.Builder(PhoneAuthProvider.PROVIDER_ID, null) .setPhoneNumber(verification.getNumber()) .build()) .build()); } @Override protected void onFailure(@NonNull Exception e) { if (e instanceof PhoneNumberVerificationRequiredException) { if (getSupportFragmentManager() .findFragmentByTag(SubmitConfirmationCodeFragment.TAG) == null) { showSubmitCodeFragment( ((PhoneNumberVerificationRequiredException) e).getPhoneNumber()); } handleError(null); } else { handleError(e); } } }); if (savedInstanceState != null) { return; } Bundle params = getIntent().getExtras().getBundle(ExtraConstants.PARAMS); CheckPhoneNumberFragment fragment = CheckPhoneNumberFragment.newInstance(params); getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_phone, fragment, CheckPhoneNumberFragment.TAG) .disallowAddToBackStack() .commit(); }