@Override
        public void onClick(View view) {
          // TODO: This depends on the OtpType enumeration to correspond to array indices for the
          // dropdown with different OTP modes.
          OtpType mode = typeTotp.isChecked() ? OtpType.TOTP : OtpType.HOTP;

          if (validateKeyAndUpdateStatus(true)) {
            String accountName = EnterKeyActivity.this.accountName.getText().toString();

            // Note that this never overwrites an existing account, and instead a counter will be
            // appended to the account name if there is a collision.
            AuthenticatorActivity.saveSecret(
                EnterKeyActivity.this,
                new AccountIndex(accountName, null), // Manually entered keys have no issuer
                getEnteredKey(),
                mode,
                AccountDb.DEFAULT_HOTP_COUNTER);

            Intent intent = new Intent(EnterKeyActivity.this, AuthenticatorActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

            finish();
          }
        }
Called when the activity is first created
java/com/google/android/apps/authenticator/otp/EnterKeyActivity.java