0

I am using createConfirmDeviceCredentialIntent() for pin authentication in my android application. If I press back button from my pin authentication intent, the createConfirmDeviceCredentialIntent closes and it displays main activity. I want that from that intent if someone presses back button the app should get closed. `KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent i = keyguardManager.createConfirmDeviceCredentialIntent("unlock", "confirm_pattern");
        try {
            startActivityForResult(i, LOCK_REQUEST_CODE);
        } catch (Exception e) {
            Log.d("exception occured", e.toString());
        }
    }    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case LOCK_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                Intent a = new Intent(MainActivity.this, HomeActivity.class);
                startActivity(a);

                textView.setText("unlock_success");
            } else {

                textView.setText("unlock_failed");
            }

            break;
    }
}`
Raj
  • 1
  • 1
  • Can't you just `finish` if you get something other than `RESULT_OK` in `onActivityResult` for this request? – Michael May 04 '18 at 10:37
  • Ya that is okay. But the issue is that, in the intent for entering the pin if the user presses back button then this intent is closed and the main activity is shown. I do'nt want the user to get into the app without authentication. – Raj May 04 '18 at 10:39
  • Like I said, can't you just override `onActivityResult` in `MainActivity` and finish the activity if the result of the credentials confirmation isn't `RESULT_OK`? – Michael May 04 '18 at 10:40
  • No, I cant do that. Because I have to display some error message when the authentication fails. i cannot finish the app at that point. – Raj May 04 '18 at 10:43
  • But you just said that you want your app to be closed if the user didn't enter their credentials. And now you're saying that you _don't_ want it to be closed. Which one is it? If you need to inform the user first, show a dialog and finish the activity once the dialog has been dismissed. – Michael May 04 '18 at 10:45
  • See, case 1) if the user does not enter the credential, and press back button on the createConfirmDeviceCredentialIntent then the app should get closed. case 2) if the user enters the right credential then he should be navigated to another activity. case 3) if the user enters wrong credentials then he should be displayed a message. – Raj May 04 '18 at 10:48
  • Ok, so aren't you getting `RESULT_CANCELED` in that case? If so, finish the activity. – Michael May 04 '18 at 10:49
  • Thanks Bro, it worked! Kudos! – Raj May 04 '18 at 10:55

0 Answers0