FMX.Platform.TApplicationEvent

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:

ItemDescriptionPlatform
AndroidiOS

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;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Delphi 2010 中调用 Lucene.Net.dll 函数可以使用 .NET 桥接技术来实现。具体步骤如下: 1. 在 Delphi 中创建一个 .NET 桥接单元,用于连接 Lucene.Net.dll。可以使用 Delphi 的 .NET 桥接工具来自动生成这个单元。在 Delphi IDE 中,选择“File”->“New”->“.NET Assembly”,然后选择 Lucene.Net.dll 文件,生成一个 .NET 桥接单元。 2. 在 Delphi 2010 中创建一个新项目,并将刚才生成的 .NET 桥接单元添加到项目中。 3. 在 Delphi 中编写代码调用 Lucene.Net.dll 中的函数。可以使用 Delphi 的 .NET 桥接技术直接访问 Lucene.Net.dll 中的类型和方法。 以下是一个简单的示例代码,演示如何使用 Delphi 2010 调用 Lucene.Net.dll 中的函数: ```delphi unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Lucene.Net.Store, Lucene.Net.Analysis.Standard, Lucene.Net.Documents, Lucene.Net.Index; {$R *.fmx} procedure TForm1.Button1Click(Sender: TObject); var dir: FSDirectory; analyzer: StandardAnalyzer; writer: IndexWriter; doc: Document; begin dir := TDirectory.GetDirectory('c:\index'); analyzer := TStandardAnalyzer.Create; writer := TIndexWriter.Create(dir, analyzer, True); doc := TDocument.Create; doc.Add(TField.Create('title', 'Delphi', TField.TERM_VECTOR_YES)); doc.Add(TField.Create('body', 'Lucene.Net.dll', TField.TERM_VECTOR_YES)); writer.AddDocument(doc); writer.Commit; writer.Close; analyzer.Close; dir.Close; Memo1.Lines.Add('Document added to index'); end; end. ``` 在这个示例中,我们使用 Delphi 2010 调用 Lucene.Net.dll 中的 IndexWriter 类来将一个文档添加到索引中。我们还使用 Lucene.Net.dll 中的 FSDirectory 和 StandardAnalyzer 类来创建索引目录和分析器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值