delphi 开发安卓时判断进入非活动  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 开发安卓时判断进入非活动


Java开发安卓时,会使用onResume及onPause处理APP的执行状态,而在使用delphi做安卓开发时,在主窗体的各事件中不能处理这对应的状态切换事件(至少目前我没找到)。

有时候,我们需要在APP暂时处于非活动状态及恢复激活时完成一些工作,为此,需要增加一个事件的响应处理。

引用 FMX.Platform

增加一个事件处理过程:

function AppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
1
其中的TApplicationEvent 是事件状态,他包括了FinishedLaunching, BecameActive, WillBecomeInactive, EnteredBackground, WillBecomeForeground, WillTerminate, LowMemory, TimeChange,对应事件状态为:完成启动,变为活动,将变为非活动,进入后台,将成为前台,将终止,低内存,时间更改。

我们需要在事件过程是判断AAppEvent的值,并编写对应的处理过程就好。

其次,需要在系统启动创建时,将事件过程指向AppEvent,从而激活事件的执行。

procedure TForm_Main.FormCreate(Sender: TObject);
var
  AppEventService: IFMXApplicationEventService;
begin
  // 增加一个窗体激活事件的响应
  if TPlatformServices.Current.SupportsPlatformService
    (IFMXApplicationEventService, AppEventService) then
    AppEventService.SetApplicationEventHandler(AppEvent);
End;

来源:https://blog.csdn.net/tanqth/article/details/109143554

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.039328098297119 seconds