如何在 iOS 和 Android 上获取应用恢复状态?
How to get app resume state on iOS and Android?
当应用程序在 iOS 和 Android[ 上恢复时,是否可以从代码的角度检查某些内容=18=]?
例如当应用程序最小化并恢复时(应用程序仍 运行 在设备后台)。
在iOS中您可以在
中添加标志
applicationDidEnterBackground
在appDelegate中知道用户是否进入后台,
applicationDidBecomeActive
知道用户 returns 从后台访问应用程序
您需要使用 IFMXApplicationEventService 注册回调,应用程序将收到通知:
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;
有关事件类型的更多信息here。
good article Paweł Głowacki 关于这个主题(对于 Delphi XE5,但仍然有用)。
当应用程序在 iOS 和 Android[ 上恢复时,是否可以从代码的角度检查某些内容=18=]?
例如当应用程序最小化并恢复时(应用程序仍 运行 在设备后台)。
在iOS中您可以在
中添加标志applicationDidEnterBackground
在appDelegate中知道用户是否进入后台,
applicationDidBecomeActive
知道用户 returns 从后台访问应用程序
您需要使用 IFMXApplicationEventService 注册回调,应用程序将收到通知:
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;
有关事件类型的更多信息here。
good article Paweł Głowacki 关于这个主题(对于 Delphi XE5,但仍然有用)。