本文介绍了如何在iOS和Android上获取应用恢复状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 iOS 和 Android 上恢复应用程序时,是否可以从代码角度检查某些内容?
Is there something that can be checked from code point of view when an App is resumed on iOS and Android?
例如当应用程序最小化和还原时(应用程序仍在设备后台运行)。
e.g. when an app gets minimized and restored (app is still running in background of device).
推荐答案
您需要使用以便注册一个将通知应用程序的回调:
You need to use IFMXApplicationEventService to register a callback where the application will be notified:
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;
有关事件类型的更多信息。
More info about the event types here.
A 关于PawełGłowacki的主题 em>(对于Delphi XE5,但仍然有用)。
A good article on the subject by Paweł Głowacki (for Delphi XE5, but still useful).
这篇关于如何在iOS和Android上获取应用恢复状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!