Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.889 Beiträge
 
Delphi 12 Athens
 
#11

AW: versehentliches Beenden einer Android App

  Alt 29. Feb 2024, 11:50
Du musst die Livecycle Events deiner App berücksichtigen!
Delphi-Quellcode:
procedure TAppForm.FormCreate(Sender: TObject);
Begin
    //Intercept LifeCycleEvents
    var aFMXApplicationEventService:IFMXApplicationEventService
    if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService) ) then
      aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
    else
      Tlog.d('Application Event Service is not supported.');
end;
Und
Delphi-Quellcode:
function TAppForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  case AAppEvent of
    TApplicationEvent.FinishedLaunching: TLog.d('FinishedLaunching'); // Only Android, Probably IOS too (App has been started by the user)
    TApplicationEvent.BecameActive: TLog.d('BecameActive'); // Both (App is in USE)
    TApplicationEvent.WillBecomeInactive: TLog.d('WillBecomeInactive'); // Only Android, Probably IOS too (Focus is about to switch to other app)
    TApplicationEvent.EnteredBackground: // Both (App is beeing executed while in the Background)
    Begin
      TLog.d('EnteredBackground');
      TAppViewModel.getinstance.EnterBackground;
    End;
    TApplicationEvent.WillBecomeForeground: // Both (App is focused)
    Begin
      TLog.d('WillBecomeForeground') ;
      TAppViewModel.getinstance.EnterForeground;
    End;
    TApplicationEvent.WillTerminate:TLog.d('WillTerminate') ; // Both (User terminted the APP)
    TApplicationEvent.LowMemory: TLog.d('LowMemory'); // Both (Please use less memory, please! But how?)
    TApplicationEvent.TimeChange:TLog.d('TimeChange') ; // IOS
    TApplicationEvent.OpenURL:TLog.d('OpenURL') ; // IOS
  end;
  Result := True;
end;
Dadurch kannst du alle Eingaben sichern befor die App beendet wird und die Eingaben wieder laden und anzeigen wenn die App fortgesetzt wird und nichts geht verloren
Andreas
Monads? Wtf are Monads?

Geändert von QuickAndDirty (29. Feb 2024 um 11:53 Uhr)
  Mit Zitat antworten Zitat