作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:如何将我的应用程序保持在前台和/或防止它永远进入后台?
我已经创建了一个应用程序并设法让它在设备启动时自动启动。该应用程序的目的是显示一些数据,除非我也想要,否则永远不会转到菜单或终止。
ActivityManager 时不时地决定我的应用程序不够重要,并希望将其发送到后台,甚至更糟的是,完全终止它。有时它会在 1、4 或 16 小时后发生。
到目前为止我已经找到了如何检查应用程序是否收到各种 ApplicationEvents:
function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.FinishedLaunching: MemoPrint('Finished Launching');
TApplicationEvent.BecameActive: MemoPrint('Became Active');
TApplicationEvent.WillBecomeInactive: MemoPrint('Will Become Inactive');
TApplicationEvent.EnteredBackground: MemoPrint('Entered Background');
TApplicationEvent.WillBecomeForeground: MemoPrint('Will Become Foreground');
TApplicationEvent.WillTerminate: MemoPrint('Will Terminate');
TApplicationEvent.LowMemory: MemoPrint('Low Memory');
end;
Result := True;
end;
procedure TForm1.LinkAppEvent;
var
aFMXApplicationEventService: IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService,
IInterface(aFMXApplicationEventService)) then
aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
else
MemoPrint('Application Event Service is not supported.');
end;
所以我想知道如何从这里开始。希望到目前为止我走在正确的轨道上。 :)
最佳答案
我不认为你可以把它放在前台。如果您想重复执行某些任务,您可以使用一个服务,该服务会在后台继续运行,即使该应用未在使用中也是如此。
您可以做的是在后台运行服务,当有新数据可用时,您可以向用户显示通知,当用户单击通知时,将显示所需的数据。就像所有新闻和其他应用所做的那样。
另外,您可以有一个处理程序,它会在特定时间间隔对您的服务器执行 ping 操作以获取新数据。但即使在那种情况下,除非或除非用户对您的应用执行某些操作,否则您无法将您的应用置于前台。
关于android - 如何将我的应用程序保留在前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28834798/
我是一名优秀的程序员,十分优秀!