[SOLVED] LAMW BackButton not working lazarus / 43-Android ---------------------------------------------------------------------- maurobio · 2023-06-03 14:28 Dear ALL, In my app, I want to intercept the back button to avoid it closing the app (which should be closed only using an appropriate menu option). However, it seems the OnBackButton event is being ignored, because even something as simple as that below does not work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.AndroidModule1BackButton(Sender: TObject);begin  ShowMessage('Back Button pressed');end; The message is not shown and the app is closed anyway. Any hints? With best regards, ---------------------------------------------------------------------- c4p · 2023-06-03 14:53 Try this on the event OnSpecialKeyDown on the main form: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (KeycodeString = 'KEYCODE_BACK') then begin   mute := true;  end; ---------------------------------------------------------------------- maurobio · 2023-06-03 18:24 Hi, @cp4! It works partially, because the app is no longer closed, but - and there is always a but! - I still cannot use the "Back" button key as its name intendes, i.e., to go back to a previous form or home page. I tried the version below, to no avail. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.AndroidModule1SpecialKeyDown(Sender: TObject;  keyChar: char; keyCode: integer; keyCodeString: string; var mute: boolean);begin  if (KeycodeString = 'KEYCODE_BACK') then  begin    mute := True;    AndroidModule1.Show;  end;end; Is there a way of making the Back Button working not only to prevent the app closing but also to go back to a certain form or home page? With warmest regards, ---------------------------------------------------------------------- c4p · 2023-06-03 20:47 Yes, that's correct, that keycodestring just recognises the Back button on your device and mute stops it exiting (cancels). I normally just close any panels or forms/modules in that event I have open and code to handle any back presses based on the conditions. I never got the BackButton event to work properly. ---------------------------------------------------------------------- maurobio · 2023-06-03 20:51 Hi, @c4p! The BackButton event is plainly ineffective. This is much regrettable. I really do hope that the LAMW developers come up with a simple solution to this annoying problem! With warmest regards, ---------------------------------------------------------------------- jmpessoa · 2023-06-03 23:04 QuoteI still cannot use the "Back" button key as its name intendes, i.e., to go back to a previous form or home page. Multi form demo: https://github.com/jmpessoa/lazandroidmodulewizard/tree/master/demos/G UI/AppTest1 ---------------------------------------------------------------------- maurobio · 2023-06-03 23:12 Hi, @c4p, @jmpessoa! I just found a direct solution here: https://stackoverflow.com/questions/6077141/how-to-go-back-to- previous-page-if-back-button-is-pressed-in-webview The code below works fine: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TAndroidModule1.AndroidModule1SpecialKeyDown(Sender: TObject;  keyChar: char; keyCode: integer; keyCodeString: string; var mute: boolean);begin  if (KeycodeString = 'KEYCODE_BACK') then  begin    if jWebView1.CanGoBack then      jWebView1.GoBack;    mute := True;  end;end; With best regards, ---------------------------------------------------------------------- c4p · 2023-06-04 06:33 Excellent.