Einzelnen Beitrag anzeigen

Rollo62

Registriert seit: 15. Mär 2007
3.910 Beiträge
 
Delphi 12 Athens
 
#11

AW: Erkennen wenn Programm "zwangsweise" beendet wird?

  Alt 18. Aug 2017, 14:28
Die ApplicationEvents die Sebastion erwähnt sind ein "Muss", sich darum zu kümmern.
Wenn du die LowMemory nicht bearbeitest wird deine App gekillt.
Bei den BecameActive, etc. bin ich nicht sicher, könnte aber auch sein das diese bearbeitet sein wollen um nicht dein Programm wieder neustarten zu lassen.

Ich mache das automatisch bei jeder App so, und die Programme können im Hintergrund weiterleben.

Delphi-Quellcode:
procedure TView_Manager.AppEvents_Subscribe;
var
  AppEventSvc: IFMXApplicationEventService;

begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(AppEventSvc)) then
    AppEventSvc.SetApplicationEventHandler(EvOnAppEvent);

end;

function TView_Manager.EvOnAppEvent(AAppEvent: TApplicationEvent;
                                      AContext: TObject): Boolean;
var
  cmd : TS4Api_SysEvents.TApi;

begin

  Result := True;

  cmd := TS4Api_SysEvents.TApi.None;

  case AAppEvent of
    TApplicationEvent.FinishedLaunching : cmd := TS4Api_SysEvents.TApi.FinishedLaunching;
    TApplicationEvent.BecameActive : cmd := TS4Api_SysEvents.TApi.BecameActive;
    TApplicationEvent.WillBecomeInactive : cmd := TS4Api_SysEvents.TApi.WillBecomeInactive;
    TApplicationEvent.EnteredBackground : cmd := TS4Api_SysEvents.TApi.EnteredBackground;
    TApplicationEvent.WillBecomeForeground: cmd := TS4Api_SysEvents.TApi.WillBecomeForeground;
    TApplicationEvent.WillTerminate : cmd := TS4Api_SysEvents.TApi.WillTerminate;
    TApplicationEvent.LowMemory : cmd := TS4Api_SysEvents.TApi.LowMemory;
    TApplicationEvent.TimeChange : cmd := TS4Api_SysEvents.TApi.TimeChange;
    TApplicationEvent.OpenURL : cmd := TS4Api_SysEvents.TApi.OpenURL;
    else
                                            ;
  end;

  if cmd <> TS4Api_SysEvents.TApi.None then
  begin
    TS4Msg_SysEvents.SendMessage(Self, cmd); // Ja ich weiss, ich leite ein Event in einen anderen Event weiter
    // Aber so kann ich diese sehr leicht abfangen und evtl. an verschiedenen Stellen verarbeiten
  end;

end;
Rollo
  Mit Zitat antworten Zitat