Recent

Author Topic: [SOLVED] LAMW BackButton not working  (Read 940 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
[SOLVED] LAMW BackButton not working
« on: June 03, 2023, 04:28:09 pm »
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][+][-]
  1. procedure TAndroidModule1.AndroidModule1BackButton(Sender: TObject);
  2. begin
  3.   ShowMessage('Back Button pressed');
  4. end;

The message is not shown and the app is closed anyway.

Any hints?

With best regards,
« Last Edit: June 04, 2023, 01:12:30 am by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 157
Re: LAMW BackButton not working
« Reply #1 on: June 03, 2023, 04:53:11 pm »
Try this on the event OnSpecialKeyDown on the main form:

Code: Pascal  [Select][+][-]
  1. if (KeycodeString = 'KEYCODE_BACK') then
  2.  begin
  3.    mute := true;
  4.  end;
  5.    
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle v8.5

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: LAMW BackButton not working
« Reply #2 on: June 03, 2023, 08:24:09 pm »
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][+][-]
  1. procedure TAndroidModule1.AndroidModule1SpecialKeyDown(Sender: TObject;
  2.   keyChar: char; keyCode: integer; keyCodeString: string; var mute: boolean);
  3. begin
  4.   if (KeycodeString = 'KEYCODE_BACK') then
  5.   begin
  6.     mute := True;
  7.     AndroidModule1.Show;
  8.   end;
  9. 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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 157
Re: LAMW BackButton not working
« Reply #3 on: June 03, 2023, 10:47:35 pm »
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.
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle v8.5

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: LAMW BackButton not working
« Reply #4 on: June 03, 2023, 10:51:35 pm »
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,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

jmpessoa

  • Hero Member
  • *****
  • Posts: 2297
Re: LAMW BackButton not working
« Reply #5 on: June 04, 2023, 01:04:17 am »
Quote
I 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/GUI/AppTest1
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Re: LAMW BackButton not working
« Reply #6 on: June 04, 2023, 01:12:12 am »
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][+][-]
  1. procedure TAndroidModule1.AndroidModule1SpecialKeyDown(Sender: TObject;
  2.   keyChar: char; keyCode: integer; keyCodeString: string; var mute: boolean);
  3. begin
  4.   if (KeycodeString = 'KEYCODE_BACK') then
  5.   begin
  6.     if jWebView1.CanGoBack then
  7.       jWebView1.GoBack;
  8.     mute := True;
  9.   end;
  10. end;
  11.  
With best regards,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

c4p

  • Full Member
  • ***
  • Posts: 157
Re: [SOLVED] LAMW BackButton not working
« Reply #7 on: June 04, 2023, 08:33:39 am »
Excellent.
Lazarus 2.0.12 r64642/FPC 3.2.0 LAMW v0.8.6.4 on Windows 10+Linux Mint 21.2, projects mainly built using AppCompat and Gradle v8.5

 

TinyPortal © 2005-2018