I am building an android app. In this snippet I am trying to call verifyKey
method, which pops up a dialog to enter a key so that it can be confirmed if it is correct and allow a message to be sent.
Unfortunately the program does not return and run from where the verifyKey
method was called. After closing the dialog I cannot find where the the program is in the code as Log.d("After verifyInvalid key", "!!!!!!!!!!!!!!!!!");
is not running. I have tried returning a boolean value from within the onClick
in verifyKey
but it is not allowing it from within a inner class. I am also getting a E/ViewRootImpl: sendUserActionEvent() mView == null
.
Is there a simple way of returning this dialog, or how would i ensure the code returns while running from the location when the dialog was called.
this.testContact = new Contacts("testCon", "08xxxxxxx", "testkey", true);
// assign on click listener to button
send_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//to send a message first an encryption key must be established
if (testContact.getKeySet()) {
verifyKey();
if (keyChecker(verifyEnteredKey)) {
Log.d("Valid key", "!!!!!!!!!!!!!!!!!");
sendSms(testContact);
} else {
Toast.makeText(getBaseContext(), "Invalid Key",
Toast.LENGTH_LONG).show();
}
Log.d("After verifyInvalid key", "!!!!!!!!!!!!!!!!!");
Log.d("OUTSDIDE KEY CEHCK", "outside");
}
}//on click
});
public boolean keyChecker(String entKey) {
if (entKey.equals(testContact.getKey())) {
Log.d("Valid key", "key confirmed");
return true;
}
Log.d("inValid key", "key un-confirmed");
return false;
}
public void verifyKey() {
verifyEnteredKey = "";
Builder builder = new Builder(SendMessage.this);
builder.setTitle("Cloaked Key");
// I'm using fragment here so I'm using getView() to provide ViewGroup
// but you can provide here any other instance of ViewGroup from your Fragment / Activity
View viewInflated = LayoutInflater.from(SendMessage.this).inflate(R.layout.key_entry_dialog, (ViewGroup) findViewById(android.R.id.content), false);
// Set up the input
final EditText input = viewInflated.findViewById(R.id.input);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
builder.setView(viewInflated);
// Set up the buttons
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
verifyEnteredKey = input.getText().toString();
Log.d("ENTERED KEYY in dialog", verifyEnteredKey);
// if(verifyEnteredKey.equals(testContact.getKey())){
// return true;
// }
// keyChecker(verifyEnteredKey);
Log.d("Before dialog dismiss", verifyEnteredKey);
dialog.dismiss();
Log.d("afteer dialog dismiss", verifyEnteredKey);
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Log.d("Before builder show", verifyEnteredKey);
builder.show();
Log.d("After builder show", verifyEnteredKey);
}