2016-07-13 10 views
2

Gibt es etwas, das von Code Sicht überprüft werden kann, wenn eine App auf iOS wieder aufgenommen wird und Android?App resume Zustand auf iOS und Android

z.B. wenn eine App minimiert und wiederhergestellt wird (App läuft noch im Hintergrund des Geräts).

Danke,

Antwort

1

Sie müssen IFMXApplicationEventService zu registrieren er einen Rückruf in dem die Anwendung benachrichtigt:

uses FMX.Types, FMX.Platform; 

function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; 
begin 
    case AAppEvent of 
    TApplicationEvent.FinishedLaunching: Log.d('Launched.'); 
    TApplicationEvent.BecameActive:   Log.d('Gained focus.'); 
    TApplicationEvent.EnteredBackground: Log.d('Now running in background.'); 
    TApplicationEvent.WillBecomeForeground: Log.d('Restoring from background.'); 
    TApplicationEvent.WillBecomeInactive: Log.d('Going to lose focus.'); 
    TApplicationEvent.WillTerminate:  Log.d('Quitting the application.'); 
    TApplicationEvent.LowMemory:   Log.d('Device running out of memory.'); 

    // iOS only 
    TApplicationEvent.TimeChange:   Log.d('Significant change in time.'); 
    TApplicationEvent.OpenURL:    Log.d('Request to open an URL.'); 
    end; 

    Result := True; 
end; 

procedure TForm11.FormCreate(Sender: TObject); 
var 
    aFMXApplicationEventService: IFMXApplicationEventService; 
begin 
    if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, 
    IInterface(aFMXApplicationEventService)) 
    then 
    aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent) 
    else 
    Log.d('Application Event Service not supported.'); 
end; 

Mehr Informationen zu den Ereignistypen here.

A good article über das Thema von Paweł Głowacki (für Delphi XE5, aber immer noch nützlich).

0

In iOS Sie Flagge

applicationDidEnterBackground 

in AppDelegate in

hinzufügen können, zu wissen, ob der Benutzer den Hintergrund und tritt,

applicationDidBecomeActive 

zu wissen, dass der Benutzer wieder Die App aus dem Hintergrund

Verwandte Themen