0
    MessageDlg('Please turn on your gps', TMsgDlgType.mtConfirmation,
    [
      TMsgDlgBtn.mbYes,
      TMsgDlgBtn.mbNo,
      TMsgDlgBtn.mbClose
    ], 0,
    procedure(const AResult: TModalResult)
    begin
      case AResult of
        mrYES: begin
          LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
          TAndroidHelper.Context.startActivity(LIntent);
        end;
        mrNo:
          Close;
        mrClose:
          Close;
        mrNone:
          Close;
      end;
    end);

Here are some code snippet I have been trying, I don't want to let the user proceed and close the app when the user click return button on the phone.

Delphi Coder
  • 1,723
  • 1
  • 14
  • 25
RenSword
  • 79
  • 8
  • It is not really clear what your question is, or what problem you are having. – Remy Lebeau Dec 14 '21 at 01:37
  • @RemyLebeau when I use yes or no in the message dialog box, its handled properly, yes will proceed, no will quit. But if I click phone back button instead of yes or no, it proceed and give wrong result. I want to make it quit like no, if back key is clicked on phone. – RenSword Dec 14 '21 at 02:06
  • I would use an `if-else` instead of a `case`, eg: `if AResult = mrYes then begin ... end else Close;` If that is not working, then you should [file a bug report](https://quality.embarcadero.com) with Embarcadero, as the phone's Return button should not trigger the callback with `mrYes`, or even skip the callback altogether. I would expect the callback to be called with `mrClose` or `mrCancel` – Remy Lebeau Dec 14 '21 at 02:08
  • Test for AResult = -1, which is what is passed if the user uses the Back (which is what I assume you meant instead of Return) button. Using a debugger would have revealed that. I recommend learning how to debug – Dave Nottage Dec 14 '21 at 02:38
  • @DaveNottage I meant return key, my bad. – RenSword Dec 14 '21 at 02:50
  • Be aware that messagedlg is deprecated as you can see [here](https://docwiki.embarcadero.com/Libraries/Sydney/en/FMX.Dialogs.MessageDlg#:~:text=Warning%3A%20MessageDlg%20is%20deprecated). You should use Platform.IFMXDialogServiceAsync.MessageDialogAsync – Xalo Dec 15 '21 at 17:32

1 Answers1

0

Thanks for everyone help. if-else case work.

    MessageDlg('Please turn on your gps', TMsgDlgType.mtConfirmation,
    [
      TMsgDlgBtn.mbYes,
      TMsgDlgBtn.mbNo
    ], 0,
    procedure(const AResult: TModalResult) begin
      if AResult = mrYES then begin
          LIntent := TJIntent.JavaClass.init(TJSettings.JavaClass.ACTION_LOCATION_SOURCE_SETTINGS);
          TAndroidHelper.Context.startActivity(LIntent);
      end
      else Close;
    end);
RenSword
  • 79
  • 8