AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Cross-Platform-Entwicklung Delphi versehentliches Beenden einer Android App
Thema durchsuchen
Ansicht
Themen-Optionen

versehentliches Beenden einer Android App

Ein Thema von pollo · begonnen am 26. Feb 2024 · letzter Beitrag vom 3. Mai 2024
Antwort Antwort
Seite 2 von 2     12   
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
MAXON

Registriert seit: 28. Aug 2009
15 Beiträge
 
#12

AW: versehentliches Beenden einer Android App

  Alt 30. Apr 2024, 23:09
Hi,
wo kommt denn das TAppViewModel her?
  Mit Zitat antworten Zitat
QuickAndDirty

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

AW: versehentliches Beenden einer Android App

  Alt 3. Mai 2024, 14:25
Hi,
wo kommt denn das TAppViewModel her?
Das ist eine Klasse in meiner Anwendung.

TAppForm ist das Main-Formular der APP

procedure TAppForm.FormCreate(Sender: TObject); ist der prozedur kopf eines OnFormCreate Ereignisses auf dem MainFormular.

Delphi-Quellcode:
    //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.');
Dieser Code hinterlegt eine Methode HandleAppEvent als Ereignis Handler für LifeCycleEvents einer Android App.
Immer wenn ein solches Event auf tritt wird die Methode HandleAppEvent von Android benachrichtigt , damit du darauf reagieren kannst.


function TAppForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; Das ist der Methoden kopf der Methode die wir als EventHandler hinterlegt haben.

Delphi-Quellcode:
  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;
Das ist ein Beispiel code dessen was man an Events im Eventhandler abfangen kann. Ich logge die meisten Events nur und wenn die Anwendung in den Hintergrund gerät schalte ich NFC und GPS ab und wenn sie in den Vordergrund kommt schalte ich es wieder ein. Ich schone damit den Akku. Für dich ist das vielleicht gar nicht wichtig .

  TApplicationEvent.WillTerminate:TLog.d('WillTerminate') ; // Both (User terminted the APP) Das Event aber vielleicht schon. Wenn dieses Event kommt kannst du noch eingreifen befor deine App stirbt.

Wenn du alle livecycle Events und das onException event deiner App loggs ist das vielleicht auch hilfreich.
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz