Einzelnen Beitrag anzeigen

DaCoda
Online

Registriert seit: 21. Jul 2006
Ort: Hamburg
80 Beiträge
 
Delphi 12 Athens
 
#6

AW: Auslesen ob die App (Android/iOS im Vordergrund läuft

  Alt 22. Jul 2022, 19:42
Ich habe es jetzt so gelöst:

Code:
{* im uses Abschnitt *}
uses
  FMX.Platform;

{im TForm-Abschnitt *}
  procedure FormCreate(Sender: TObject);
private
  AppIsEnabled: Boolean;
  function HandleAppEvent(   AAppEvent : TApplicationEvent;  AContext : TObject ) : Boolean;

[* im Implementation - Abschnitt *}
procedure TfrmMain.FormCreate(Sender: TObject);
var
  SvcEvents : IFMXApplicationEventService;
begin
    if TPlatformServices.Current.SupportsPlatformService
      ( IFMXApplicationEventService, IInterface( SvcEvents ) )
    then
      SvcEvents.SetApplicationEventHandler( HandleAppEvent );
end;


function TfrmMain.HandleAppEvent(   AAppEvent : TApplicationEvent;  AContext : TObject ) : Boolean;
begin
    case AAppEvent of
      TApplicationEvent.FinishedLaunching : ;
      TApplicationEvent.BecameActive : AppIsEnabledEnabled := True;
      TApplicationEvent.WillBecomeInactive : ;
      TApplicationEvent.EnteredBackground : AppIsEnabled := False;
      TApplicationEvent.WillBecomeForeground : ;
      TApplicationEvent.WillTerminate : ;
      TApplicationEvent.LowMemory : ;
      TApplicationEvent.TimeChange : ;
      TApplicationEvent.OpenURL : ;
    end;
    Result := True;
end;
Scheint so korrekt zu funktionieren, vielleicht kann es ja mal jemand brauchen.

Lieben Dank für Eure Tipps!
Debuggers don’t remove bugs, they only show them in slow-motion.

Geändert von DaCoda (22. Jul 2022 um 19:44 Uhr)
  Mit Zitat antworten Zitat