0

I'm using an account picker for my Android App.

Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null);
startActivityForResult(intent, REQUEST_CODE_EMAIL);

This is all working fine. But i want to know, if it is possible to force the user to hit 'OK' or 'Cancel'. Currently if the user clicks outside this dialog, it's the same as hitting cancel.

Is there a way to make the dialog modal to force the user click either 'ok' or 'cancel'.

In my opinion it's too easy to cancel this dialog, somethimes this happens unintentionally and then the dialog is gone.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kaiser
  • 940
  • 1
  • 10
  • 25

1 Answers1

0

If you have an Activity (even if it looks like a Dialog), then you should do

this.setFinishOnTouchOutside(false);

if you have used Dialog class, you should call

dialog.setFinishOnTouchOutside(false)

if you want to prevent closing it when the background activity is clicked. Hope it helps.

Sahil
  • 952
  • 1
  • 7
  • 14
  • Thanks, i think that is the way to go. Do you know, how i can hook the Activity that is started from startActivityForResult – kaiser Mar 03 '19 at 15:42
  • sure, this is very well explained here https://stackoverflow.com/a/10407371/5906447 – Sahil Mar 03 '19 at 15:49
  • In my case, the intent is not created by me. The intent is created from newChooseAccountIntent(...) – kaiser Mar 03 '19 at 16:12
  • above code is to be written in activity or dialog class, provide more information in case you cant access that class directly in your code base. – Sahil Mar 03 '19 at 16:35
  • Sorry i don't get it. If i put "this.setFinishOnTouchOutside(false);" directly below my upper code, it's not working (seems clear to me, it's the wrong acitivity). But I cannot set an Activity for upper Intent. The intent is created by https://developers.google.com/android/reference/com/google/android/gms/common/AccountPicker. – kaiser Mar 03 '19 at 16:47
  • My bad buddy, this is a google api, you won't be able to handle it the way you want. All you can do is to make sure that user could not pass through app flow until it chooses an account. Since you can't access the class you won't be able to change its cancellabe property. – Sahil Mar 03 '19 at 16:59
  • Thanks for your help so far. Then my question stays open. I don't want to force the user to choose an account. I just want to force him to hit "OK" or "CANCEL". This is a mental thing. As is my Question: "In my opinion it's too easy to cancel this dialog, somethimes this happens unintentionally and then the dialog is gone." If they hit cancel, i'm fine with that. Also there is no difference between cancel and clicking off the dialog ... – kaiser Mar 03 '19 at 17:03