XE5: Does my Android app will need a TTimer to timeout and force it to close? What I mean is that when I go to the home and dont return the app keep going running.
XE5: Does my Android app will need a TTimer to timeout and force it to close? What I mean is that when I go to the home and dont return the app keep going running.
Other question, same subject: how can I prevent the OS to kill my task when in bg? Can we develop a system service with Delphi that will/can start the app?
Other question, same subject: how can I prevent the OS to kill my task when in bg? Can we develop a system service with Delphi that will/can start the app?
>>Other question, same subject: how can I prevent the OS to kill my task when in bg?
ReplyDeleteyou can't, the os is the supervisor, it can pause your app, kill it, make it it's slave, modify code at runtime, prevent access, anything it wants really...
You're suppose to suspend all unnecessary activities in your app when it loses focus (even for short periods), so as to conserve battery.
ReplyDeleteYou're not supposed to close it, the OS will do that when memory gets low, if it doesn't, your app should wait in its suspended state so that it can be brought back into focus faster if the user switches tasks.
It's possible to develop Android services, but they're intended for background tasks (such as handling notifications, tracking geolocation, etc.)
AFAIK currently services cannot be written with delphi
ReplyDeleteThank you for that.
ReplyDeleteSo, best technique is to force close after a while when user goes home and dont returns, I say that because my app depends on accessing database to retrieve its info.
Force close shouldn't be required. Just act like an Android app. Stop accessing DB stuff and other activities when you head to the background. Start up again when you come to the foreground.
ReplyDeleteUse something like this to detect switching to/from background, no?
uses
FMX.Platform, FMX.Types;
...
function ApplicationEventHandler(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
...
AppEvents: IInterface;
...
function TMainForm.ApplicationEventHandler(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
Log.d('', Self, 'ApplicationEventHandler', Format('%s',
[GetEnumName(TypeInfo(TApplicationEvent), Integer(AAppEvent))]));
Result := True;
case AAppEvent of
aeWillBecomeForeground, aeBecameActive: ForegroundMode := True;
aeWillBecomeInactive, aeEnteredBackground: ForegroundMode := False;
end;
end;
...
if TPlatformServices.Current.SupportsPlatformService(
IFMXApplicationEventService,
AppEvents) then
AppEvents.SetApplicationEventHandler(
ApplicationEventHandler);
Thank you the code! It will be very usefull
ReplyDeleteEvent type "aeEnteredForeground" should be into FMX.Platform? I put that to run
ReplyDeleteOops. My bad. Let me just edit the code posted in that comment...
ReplyDeleteThere, try that.