[英]How can I keep my application in the foreground?
問題:如何將我的應用程序置於前台和/或阻止其進入后台?
我創建了一個應用程序並設法讓它在設備啟動時自動啟動。 該應用程序的目的是顯示一些數據,永遠不會去菜單或終止,除非我也想要它。
每隔一段時間,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;
所以我想知道如何從這里開始。 希望到目前為止我在正確的軌道上。 :)
我不認為你可以把它保持在前台。 如果您想重復執行某項任務,即使應用程序未在使用中,您也可以使用即時在后台運行的服務。
您可以做的是在后台運行服務,當有新數據可用時,您可以向用戶顯示通知,當用戶點擊通知時,將顯示所需的數據。 像所有新聞和其他應用程序一樣。
此外,您可以使用Handler,以特定的時間間隔為您的服務器提供新數據。 但即使在這種情況下,您也無法將應用程序帶到前台,除非用戶對您的應用程序執行某些操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.