AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Delphi-PRAXiS - Lounge Delphi-News aus aller Welt Gestion de eventos en una aplicación
Thema durchsuchen
Ansicht
Themen-Optionen

Gestion de eventos en una aplicación

Ein Thema von DP News-Robot · begonnen am 2. Mär 2019
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
14.964 Beiträge
 
#1

Gestion de eventos en una aplicación

  Alt 2. Mär 2019, 20:30


Cuando programamos una app, necesitamos gestionar diferentes eventos que suceden durante su ejecución.
Por ejemplo, si la memoria del dispositivo es baja, tendríamos que avisar al usuario y posteriormente cerrar la app (en el caso de que tengamos una base de datos abierta, para evitar el cierre inesperado de la misma)
Otro suceso que necesitamos conocer, es saber cuando nuestra app se ejecuta en background, ya que si esto sucede y estamos utilizando el GPS, éste último dejaría de actualizar las coordenadas.
También nos interesa saber cuando el usuario cierra la app, ya que deberíamos cerrar en ese momento las bases de datos abiertas.
Para solucionar este tema Delphi nos ofrece una serie de procedimientos para controlarlo, que están en la unit FMX.Platform.TApplicationEvent.


TApplicationEvent = (FinishedLaunching, BecameActive, WillBecomeInactive, EnteredBackground, WillBecomeForeground, WillTerminate, LowMemory, TimeChange, OpenURL);

Para utilizarlo creamos en primer lugar una variable global llamada AppEventSvc

var
AppEventSvc: IFMXApplicationEventService;

En el oncreate del Form escribimos lo siguiente:

if TPlatformServices.Current.SupportsPlatformService( IFMXApplicationEventService, IInterface(AppEventSvc)) then

AppEventSvc.SetApplicationEventHandler(AppEvent);


y a continuación escribimos el procedimiento que va a manejar los eventos:

function TForm1.AppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;

begin

Result := True;

case AAppEvent of

TApplicationEvent.WillBecomeInactive:
//procedimiento que se ejecuta cuando la app este inactiva
;
TApplicationEvent.EnteredBackground: //procedimiento que se ejecuta cuando la app se ejecute en background ;
TApplicationEvent.WillTerminate: //procedimiento que se ejecuta cuando la app se va a cerrar ;
end;
end;

Tienen mas información el el docwiki de Embarcadero Suscribirse :



Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


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 20:21 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