FMX.Platform.TApplicationEvent

http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Platform.TApplicationEvent

http://docwiki.embarcadero.com/Libraries/Tokyo/en/FMX.Platform.TApplicationEvent

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

An instance of TApplicationEvent may have any of the following values:

Item Description Platform
Android iOS

BecameActive

Your application has gained the focus.//applicationDidBecomeActive

Supported

Supported

EnteredBackground

The user is no longer using your application, but your application is still running in the background.

Supported

Supported

FinishedLaunching

Your application has been launched.

Supported

Supported

LowMemory

This warns your application that the device is running out of memory.

Your application should reduce memory usage, freeing structures and data that can be loaded again at a later point.

Supported

Supported

OpenURL

You application has received a request to open an URL.

Application events of this type are usually associated with a context. This context is an instance of the iOS-only TiOSOpenApplicationContext class, which provides the following read-only properties:

  • TiOSOpenApplicationContext.SourceApp is a string that contains the bundle ID of the application that requested your application to open the URL.
  • TiOSOpenApplicationContext.URL is the URL to open, either a network resource or a file.
  • TiOSOpenApplicationContext.Context is a pointer to a property-list object that might provide additional information.

See the iOS API reference documentation for more information.

 

Supported

TimeChange

There has been a significant change in time.

This event might happen for example when the day changes or when the device changes to or from daylight savings time.

 

Supported

WillBecomeForeground

The user is now using your application, which was previously in the background.

Supported

Supported

WillBecomeInactive

Your application is going to loose the focus. / applicationWillResignActive

Supported

Supported

WillTerminate

The user is quitting your application.

Supported

Supported

http://codeverge.com/embarcadero.delphi.ios/ifmxapplicationeventservice-not-firing/2028062

http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583
procedure TMainForm.FormCreate(Sender: TObject); var SvcEvents: IFMXApplicationEventService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then SvcEvents.SetApplicationEventHandler(HandleAppEvent); Application.OnException := ExceptionHandler; end; function TMainForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; begin case AAppEvent of TApplicationEvent.FinishedLaunching: ; TApplicationEvent.BecameActive: ; TApplicationEvent.WillBecomeInactive: ; TApplicationEvent.EnteredBackground: ; TApplicationEvent.WillBecomeForeground: ; TApplicationEvent.WillTerminate: ; TApplicationEvent.LowMemory: ; TApplicationEvent.TimeChange: ; TApplicationEvent.OpenURL: ; end; Result := True; end; - See more at: http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583#sthash.6XM5jEUI.dpuf
procedure TMainForm.FormCreate(Sender: TObject); var SvcEvents: IFMXApplicationEventService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then SvcEvents.SetApplicationEventHandler(HandleAppEvent); Application.OnException := ExceptionHandler; end; function TMainForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; begin case AAppEvent of TApplicationEvent.FinishedLaunching: ; TApplicationEvent.BecameActive: ; TApplicationEvent.WillBecomeInactive: ; TApplicationEvent.EnteredBackground: ; TApplicationEvent.WillBecomeForeground: ; TApplicationEvent.WillTerminate: ; TApplicationEvent.LowMemory: ; TApplicationEvent.TimeChange: ; TApplicationEvent.OpenURL: ; end; Result := True; end; - See more at: http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583#sthash.6XM5jEUI.dpuf

procedure TMainForm.FormCreate(Sender: TObject); var SvcEvents: IFMXApplicationEventService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then SvcEvents.SetApplicationEventHandler(HandleAppEvent); Application.OnException := ExceptionHandler; end; function TMainForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; begin case AAppEvent of TApplicationEvent.FinishedLaunching: ; TApplicationEvent.BecameActive: ; TApplicationEvent.WillBecomeInactive: ; TApplicationEvent.EnteredBackground: ; TApplicationEvent.WillBecomeForeground: ; TApplicationEvent.WillTerminate: ; TApplicationEvent.LowMemory: ; TApplicationEvent.TimeChange: ; TApplicationEvent.OpenURL: ; end; Result := True; end; - See more at: http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583#sthash.6XM5jEUI.dpuf

http://community.embarcadero.com/index.php/blogs/entry/mobile-app-lifecycle-events-handling-in-delphi-xe5-40067

http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583

FMX.Platform.pas

procedure TMainForm.FormCreate( Sender : TObject );
var
SvcEvents : IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService
( IFMXApplicationEventService, IInterface( SvcEvents ) )
then
SvcEvents.SetApplicationEventHandler( HandleAppEvent );
Application.OnException := ExceptionHandler;
end; function TMainForm.HandleAppEvent( AAppEvent : TApplicationEvent; AContext : TObject ) : Boolean;
begin
case AAppEvent of
TApplicationEvent.FinishedLaunching :
;
TApplicationEvent.BecameActive :
;//第一次运行app触发,从后台切换过来也触发
TApplicationEvent.WillBecomeInactive :
;
TApplicationEvent.EnteredBackground :
;//切换到后台
TApplicationEvent.WillBecomeForeground :
;//从后台切换到前台
TApplicationEvent.WillTerminate :
;
TApplicationEvent.LowMemory :
;
TApplicationEvent.TimeChange :
;
TApplicationEvent.OpenURL :
;
end;
Result := True;
end;
//See more at : http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583

和IOS的对比

 
/app启动完毕调用,应用初次启动
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//进入后台时调用:一般在这里保存应用数据(游戏数据,比如暂停游戏)
- (void)applicationDidEnterBackground:(UIApplication *)application 连续点击两次Home按钮
在任务栏点击SpringBoard或者按下Home按钮,单次点击Home按钮

- (void)applicationWillResignActive:(UIApplication *)application

//程序回到前台时调用,恢复数据
- (void)applicationWillEnterForeground:(UIApplication *)application
//接收内存警告时候调用
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
//程序即将退出
- (void)applicationWillTerminate:(UIApplication *)application
//程序获取焦点,在任务栏中回到app
- (void)applicationDidBecomeActive:(UIApplication *)application

procedure TMainForm.FormCreate(Sender: TObject); var SvcEvents: IFMXApplicationEventService; begin if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then SvcEvents.SetApplicationEventHandler(HandleAppEvent); Application.OnException := ExceptionHandler; end; function TMainForm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean; begin case AAppEvent of TApplicationEvent.FinishedLaunching: ; TApplicationEvent.BecameActive: ; TApplicationEvent.WillBecomeInactive: ; TApplicationEvent.EnteredBackground: ; TApplicationEvent.WillBecomeForeground: ; TApplicationEvent.WillTerminate: ; TApplicationEvent.LowMemory: ; TApplicationEvent.TimeChange: ; TApplicationEvent.OpenURL: ; end; Result := True; end; - See more at: http://codeverge.com/embarcadero.delphi.firemonkey/keep-application-on-top/2009583#sthash.6XM5jEUI.dpuf

跟踪的时间触发日志。

FormCreate
FormShow
BecameActive

FormSaveState
EnteredBackgrounbd
WillBecomeForeground

BecameActive

FormSaveState
EnteredBackgrounbd

WillBecomeForeground
BecameActive

FormSaveState
EnteredBackgrounbd

WillBecomeForeground
BecameActive

function TFMXMusicPlayerFrm.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
var
astate: string;
begin
case AAppEvent of
TApplicationEvent.FinishedLaunching:
astate := 'FinishedLaunching';
TApplicationEvent.BecameActive:
astate := 'BecameActive';
TApplicationEvent.WillBecomeInactive:
astate := 'WillBecomeInactive';
TApplicationEvent.EnteredBackground:
astate := 'EnteredBackground';
TApplicationEvent.WillBecomeForeground:
astate := 'WillBecomeForeground';
TApplicationEvent.WillTerminate:
astate := 'WillTerminate';
TApplicationEvent.LowMemory:
astate := 'LowMemory';
TApplicationEvent.TimeChange:
astate := 'TimeChange';
TApplicationEvent.OpenURL:
astate := 'OpenURL';
end;   Result := true;
end;

FMX.Platform.iOS.pas

Application delegates

  TApplicationDelegate = class{(TOCLocal, UIApplicationDelegate)}
private
FMainWindow: TFMXWindow;
public
function application(Sender: UIApplication; didFinishLaunchingWithOptions: NSDictionary): Boolean; overload; cdecl;
procedure application(Sender: UIApplication; didReceiveLocalNotification: UILocalNotification); overload; cdecl;
procedure application(Sender: UIApplication; didRegisterForRemoteNotificationsWithDeviceToken: NSData); overload; cdecl;
function application(const openURL, sourceApplication: string; annotation: Pointer): Boolean; overload; cdecl;
procedure applicationDidBecomeActive(const Sender: UIApplication); cdecl;
procedure applicationDidEnterBackground(const Sender: UIApplication); cdecl;
procedure applicationDidRegisterForRemoteNotificationsWithDeviceToken(Sender: UIApplication; AToken: NSData); cdecl;
procedure applicationDidReceiveRemoteNotification(Sender: UIApplication; ANotification: NSDictionary); cdecl;
procedure didFailToRegisterForRemoteNotificationsWithError(Sender: UIApplication; AError: NSError); cdecl;
procedure applicationDidReceiveMemoryWarning(Sender: UIApplication); cdecl;
procedure applicationSignificantTimeChange(Sender: UIApplication); cdecl;
procedure applicationWillEnterForeground(Sender: UIApplication); cdecl;
procedure applicationWillResignActive(Sender: UIApplication); cdecl;
procedure applicationWillTerminate(Sender: UIApplication); cdecl;
procedure setWindow(window: UIWindow); cdecl;
function window: UIWindow; cdecl;
property MainWindow: TFMXWindow read FMainWindow;
end;
// Application delegates

function applicationDidFinishLaunchingWithOptions(self: id; _cmd: SEL;
application: PUIApplication; options: PNSDictionary): Boolean; cdecl;
begin
Result := PlatformCocoa.FAppDelegate.application(TUIApplication.Wrap(application), TNSDictionary.Wrap(options));
end; procedure applicationDidReceiveLocalNotification(self: id; _cmd: SEL; application: PUIApplication;
notification: Pointer); cdecl;
begin
PlatformCocoa.FAppDelegate.application(TUIApplication.Wrap(application), TUILocalNotification.Wrap(notification));
end; procedure didReceiveRemoteNotification(self: id; _cmd: SEL; app: PUIApplication; ANotification: PNSDictionary); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationDidReceiveRemoteNotification(TUIApplication.Wrap(app), TNSDictionary.Wrap(ANotification));
end; procedure didFailToRegisterForRemoteNotificationsWithError(self: id; _cmd: SEL; app: PUIApplication; error: PNSError); cdecl;
begin
PlatformCocoa.FAppDelegate.didFailToRegisterForRemoteNotificationsWithError(TUIApplication.Wrap(application), TNSError.Wrap(error));
end; procedure didRegisterForRemoteNotificationsWithDeviceToken(self: id; _cmd: SEL; application: PUIApplication; deviceToken: PNSData); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationDidRegisterForRemoteNotificationsWithDeviceToken(TUIApplication.Wrap(application), TNSData.Wrap(deviceToken));
end; procedure applicationOpenURLWithSourceAnnotation(self: id; _cmd: SEL; application: PUIApplication; url: Pointer; sourceApplication: PNSString; annotation: id);
var
URLString: string;
SourceAppString: string;
begin
if url <> nil then
URLString := NSStrToStr(TNSURL.Wrap(url).absoluteString)
else
URLString := '';
if sourceApplication <> nil then
SourceAppString := NSStrToStr(TNSString.Wrap(sourceApplication))
else
SourceAppString := '';
PlatformCocoa.FAppDelegate.application(URLString, SourceAppString, annotation);
end; procedure applicationDidBecomeActive(self: id; _cmd: SEL; application: PUIApplication); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationDidBecomeActive(TUIApplication.Wrap(application));
end; procedure applicationDidEnterBackground(self: id; _cmd: SEL; application: PUIApplication); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationDidEnterBackground(TUIApplication.Wrap(application));
end; procedure applicationWillEnterForeground(self: id; _cmd: SEL; application: PUIApplication); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationWillEnterForeground(TUIApplication.Wrap(application));
end; procedure applicationWillTerminate(self: id; _cmd: SEL; application: PUIApplication); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationWillTerminate(TUIApplication.Wrap(application));
end; procedure applicationDidReceiveMemoryWarning(self: id; _cmd: SEL; application: PUIApplication); cdecl;
begin
PlatformCocoa.FAppDelegate.applicationDidReceiveMemoryWarning(TUIApplication.Wrap(application));
end;

FMX.Platform.TApplicationEvent的更多相关文章

  1. 如何处理App的Application的事件

    http://blog.sina.com.cn/s/blog_44fa172f0102vwr2.html 直接上代码,还有条经验就是SetApplicationEventHandler可注册多个事件方 ...

  2. FMX App的Application的事件(各种手机的全局按键)

    直接上代码,还有条经验就是SetApplicationEventHandler可注册多个事件方法. unit Unit6; interface uses  System.SysUtils, Syste ...

  3. 一个支持FMX.Win框架的托盘控件

    不多说了 直接上代码........有任何问题请给我邮件.... // **************************************************************** ...

  4. XE6 FMX之控件绘制与显示

    中午,有个货随手买的2块钱的彩票,尼玛中了540块,这是啥子狗屎气运.稍微吐槽一下,现在开始正规的笔记录入.经常有朋友说为毛我的博客不更新了或者说更新的少了,为啥呢!一来自己懒了,没学习什么新的东西, ...

  5. 应用程序的关闭退出(在FMX中,Activity替代了Form的概念)

    在VCL中,关闭程序的主窗体也就意味着程序的主循环结束,主程序自然而然结束.所以在主窗体中使用窗体的关闭函数(Close)即可,如下: procedure TfrmMain.btncloseClick ...

  6. 关于Delphi XE2的FMX的一点点研究之消息篇

    Delphi XE2出来了一阵子了,里面比较抢眼的东西,除了VCLStyle这个换肤的东西之外,另外最让人眼亮的应该是FMX这个东西了.万一的博客上都连载了一票的关于FMX的使用心得了.我还是没咋去关 ...

  7. [FMX]在你的跨平台应用中使用剪贴板进行复制粘贴

    [FMX]在你的跨平台应用中使用剪贴板进行复制粘贴 2017-08-10 • Android.C++ Builder.Delphi.iOS.教程 • 暂无评论 • swish •浏览 516 次 VC ...

  8. FMX+Win32,窗口无法保持原样,应该是个bug

    从FMX发布开始,一直有这问题,大家看看是不是一个bug,应该如何修复? 新建一个FMX Application,运行后,点击窗口标题栏右上角的“最大化”按钮,此时窗口是最大化的.在windows最底 ...

  9. Delphi XE5 android 捕获几个事件

    以下代码能监控到以下几个事件: FinishedLaunching     BecameActive     WillBecomeInactive    EnteredBackground    Wi ...

随机推荐

  1. NPOI-Excel系列-1000.创建一个标准的Excel文件

    using NPOI.HSSF.UserModel; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; name ...

  2. http://www.bootcss.com/p/font-awesome/

    集成 将Font Awesome 集成到 Bootstrap 非常容易,还可以被单独使用. 最简单的 Bootstrap + Font Awesome 集成方式 使用这种方式将 Font Awesom ...

  3. 5月24日上课笔记-js操作DOM

    解析properpties配置文件 类加载器 ResourceBundle 一.jquery操作DOM 1.jquery操作css css("",""); cs ...

  4. Axure RP Extension for Chrome经常损坏

    昨天自己修改后的谷歌浏览器插件,才使用了一天,今天刚打开浏览器就弹出了“已停用不支持的扩展程序”提示,第三方扩展程序就这么不受谷歌浏览器待见呢!?好吧,想办法解决! 通过扩展程序里“该扩展程序未列在 ...

  5. MATLAB 条形图或饼状图 图案填充

    function [im_hatch,colorlist] = applyhatch_pluscolor(h,patterns,CvBW,Hinvert,colorlist, ... dpi,hatc ...

  6. c#二维码建立与识别

    QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.CharacterSet = "UTF-8" ...

  7. 跨域资源共享/option 请求产生原因

    https://blog.csdn.net/hfahe/article/details/7730944

  8. 一个简单的MVVM雏形

    这是@尚春实现的MVVM,使用定时器轮询,只支持{{}}与input.value的修改. 这只能算是一个玩具,真正的MVVM需要有更复杂的扫描机制,JS解析器,双向绑定链什么的. <!DOCTY ...

  9. 第一个独特字符位置 · first position unique character

    [抄题]: 给出一个字符串.找到字符串中第一个不重复的字符然后返回它的下标.如果不存在这样的字符,返回 -1. 给出字符串 s = "lintcode",返回 0.给出字符串 s ...

  10. 单词搜索 II · Word Search II

    [抄题]: 给出一个由小写字母组成的矩阵和一个字典.找出所有同时在字典和矩阵中出现的单词.一个单词可以从矩阵中的任意位置开始,可以向左/右/上/下四个相邻方向移动. 给出矩阵: doafagaidca ...