@Override
 public void onResume() {
   super.onResume();
   try {
     findView(Button.class, R.id.pk_generate_button)
         .setOnClickListener(
             new View.OnClickListener() {
               public void onClick(View view) {
                 onGenerateClicked(view);
               }
             });
   } catch (ViewNotFoundException e) {
     log.error(e.getMessage(), e);
   }
 }
  public void onGenerateClicked(View view) {
    try {
      log.debug("Key name {}", getKeyName());
      log.debug("Key type {}", getKeyType());
      log.debug("Key bits {}", getKeyBits());

      KeyChain.getInstance(getActivity())
          .generateKeyAsync(getKeyName(), getKeyType(), getKeyBits());
      getActivity()
          .finish(); // this has to be changed if we are using single activity at some point
    } catch (InvalidInputException e) {
      log.warn("TODO: handle specific cases");
      Toast.makeText(getActivity(), R.string.pk_invalid_input, Toast.LENGTH_SHORT).show();
    } catch (ViewNotFoundException e) {
      log.error(e.getMessage(), e);
    } catch (KeyStoreException e) {
      log.error(e.getMessage(), e);
    }
  }