|
Replies:
12
-
Last Post:
Feb 1, 2018 8:46 PM
Last Post By: madammar ellias
|
|
|
Posts:
111
Registered:
8/17/17
|
|
i have this empty app that compiled with delphi seattle
unit Unit3;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.IOUtils, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.Media, FMX.StdCtrls, FMX.ScrollBox, FMX.Memo,
FMX.Helpers.Android, Androidapi.JNI.Net, FMX.Platform,
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.Os,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.Media,
Androidapi.Helpers,
Androidapi.JNI.App, Androidapi.JNI,
FMX.Platform.Android, Androidapi.JNI.PowerManager;
type
TForm3 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
procedure Logdatas(sdata: string);
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.fmx}
procedure TForm3.Logdatas(sdata: string);
begin
memo1.lines.add(sdata);
end;
function TForm3.HandleAppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
case AAppEvent of
TApplicationEvent.FinishedLaunching:
Logdatas('Finished Launching');
TApplicationEvent.BecameActive:
Logdatas('IsActive');
TApplicationEvent.WillBecomeInactive:
Logdatas('Inactive');
TApplicationEvent.EnteredBackground:
Logdatas('IsBackground');
TApplicationEvent.WillBecomeForeground:
Logdatas('IsForeground');
TApplicationEvent.WillTerminate:
Logdatas('Terminate');
TApplicationEvent.LowMemory:
Logdatas('Low Memory');
TApplicationEvent.TimeChange:
Logdatas('Time Change');
TApplicationEvent.OpenURL:
Logdatas('Open URL');
end;
Result := True;
end;
procedure TForm3.FormCreate(Sender: TObject);
var
aFMXApplicationEventService: IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService
(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
begin
aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent);
end;
AcquireWakeLock;
end;
end.
app runs fine when it goes to background and keep running normally.
but if the app in the background and if i turn the screen off from power button the app closed any idea how to solve this problem ?
i tested apps like whatsapp and facebook and did the same thing with them and they are running normally
|
|
|
Posts:
111
Registered:
8/17/17
|
|
it seems like application got recreated each time the screen turns off any one else have this issue or just me ?
|
|
|
|
Posts:
33
Registered:
12/16/07
|
|
So what 'Logdata' message do you actually see?
And what Android version?
Bart
i have this empty app that compiled with delphi seattle me thing with them and they are running normally
--
---
Bart Kindt
CEO & Developer
SARTrack Limited New Zealand
http://www.sartrack.nz
|
|
|
|
Posts:
111
Registered:
8/17/17
|
|
So what 'Logdata' message do you actually see?
And what Android version?
Bart
i have this empty app that compiled with delphi seattle me thing with them and they are running normally
--
---
Android version 6 logdata catch "inactive,background" then after turn of the screen app restarted so i couldn't see the latest results , i have been testing this also on berlin without any logging just create empty app run it then bring the phone to inactive by pressing home button then turn off the screen from power button for a minute or more then try to come back to the app it will restarted .
|
|
|
|
Posts:
33
Registered:
12/16/07
|
|
Okay listen: Android will simply close any App which is not in the foreground, when it feels like it.
It will feel like it when it thinks there are to many other Apps busy and taking resources, when it is getting low on memory, or many other reasons.
As soon as your App (_Client_) is no longer in the foreground, anything can happen to it, over which you have no control. The later the version of Android, the faster it will be killed off
If you want to make absolutely sure something keeps working in the background, you MUST start using a "Service" and this is not an easy task.
Even then, you must tell Android the Service is "Sticky" (it should restart it when it first kills it... don't ask me why it then kills it in the first place) and the communication between your actual App (client) and the Service is not easy at all.... But it is the only way.
Its not like a Windows program at all...
Bart
Android version 6 logdata catch "inactive,background" then after turn of the screen app restarted so i couldn't see the latest results , i have been testing this also on berlin without any logging just create empty app run it then bring the phone to inactive by pressing home button then turn off the screen from power button for a minute or more then try to come back to the app it will restarted .
--
---
Bart Kindt
CEO & Developer
SARTrack Limited New Zealand
http://www.sartrack.nz
|
|
|
|
Posts:
111
Registered:
8/17/17
|
|
Okay listen: Android will simply close any App which is not in the foreground, when it feels like it.
It will feel like it when it thinks there are to many other Apps busy and taking resources, when it is getting low on memory, or many other reasons.
As soon as your App (_Client_) is no longer in the foreground, anything can happen to it, over which you have no control. The later the version of Android, the faster it will be killed off
If you want to make absolutely sure something keeps working in the background, you MUST start using a "Service" and this is not an easy task.
Even then, you must tell Android the Service is "Sticky" (it should restart it when it first kills it... don't ask me why it then kills it in the first place) and the communication between your actual App (client) and the Service is not easy at all.... But it is the only way.
Its not like a Windows program at all...
Bart
--
---
Bart Kindt
CEO & Developer
SARTrack Limited New Zealand
http://www.sartrack.nz
so an empty app cannot be in background ? then its not fmx issue i am already migrating to B4A "Basic 4 android" i am only making sure that i am doing the right decision and its not more firemonkey bug
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
madammar ellias wrote:
so an empty app cannot be in background ?
As Bart advised, it's possible that apps in the background can be terminated by the OS, so if you require the code to
keep running, you'll need a service.
then its not fmx issue i am already migrating to B4A "Basic 4 android" i am
only making sure that i am doing the right decision and its not more firemonkey bug
It's not a Firemonkey bug; it's an OS requirement, so it won't matter what dev tool you use.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
Bart Kindt wrote:
If you want to make absolutely sure something keeps working in the background, you MUST start using a "Service" and
this is not an easy task.
I find it easy to add a service to an Android app. The hard (read: time consuming) part is managing a cross-platform
project that uses an Android service on Android.
Even then, you must tell Android the Service is "Sticky" (it should restart it when it
first kills it... don't ask me why it then kills it in the first place) and the communication between your actual
App (client) and the Service is not easy at all....
That part is not trivial, however it's also not rocket science. It also can be done one of 2 ways: either by "binding"
to the service, or by sending local broadcasts, which is what I do in this demo:
https://github.com/DelphiWorlds/KastriFree/tree/master/Demos/AndroidLocation
i.e. the DoMessage part in Service/LS.ServiceModule.pas and use of the TServiceMessageReceiver class in
Application/LA.MainFrm.pas.
Note that the demo requires other files from the Kastri Free project.
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
111
Registered:
8/17/17
|
|
I find it easy to add a service to an Android app. The hard (read: time consuming) part is managing a cross-platform
project that uses an Android service on Android.
me as well i don't find any difficult using service under firemonkey , the demonstrate you have created is very helpful for local service to share strings .
currently i am not using firemonkey for android apps. but it will be helpful if the demonstrate add more info about sharing memorystream from service to host app
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
madammar ellias wrote:
it will be helpful if the demonstrate add more info about sharing memorystream from service to host app
That would definitely require binding to the service, which is still relatively trivial (but still takes work), however
I would first be asking why passing a memory stream to the app is required in the first place, i.e. why does the app
absolutely need it in that form?
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
111
Registered:
8/17/17
|
|
I would first be asking why passing a memory stream to the app is required in the first place, i.e. why does the app
absolutely need it in that form?
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Service are used for longtime running apps and handle background tasks , what if i run in the service a client such as Rest/http/tcp/udp etc to send and receive some data which i need the host app to read from the service.
the possible way that i used in Fire monkey is that data in memory stream can be saved to the disk and the host app can periodically read it , but this is not an efficient way to communicate between the host app and its service which eat the phone memory and not reliable as it should be.
sending any data from the service to its host app directly is the way that should be handled and more reliable , i do that in B4A easily which in Firemonkey this is not possible or maybe possible and need hard work and developer tweaks .
|
|
|
|
Posts:
1,850
Registered:
1/7/00
|
|
madammar ellias wrote:
Service are used for longtime running apps and handle background tasks , what if i run in the service a client such
as Rest/http/tcp/udp etc to send and receive some data which i need the host app to read from the service.
the possible way that i used in Fire monkey is that data in memory stream can be saved to the disk and the host app
can periodically read it..
..or you could send a message to the app informing it what the filename is. Once the file is handled by the app it
could delete it, thus not "eating memory".
sending any data from the service to its host app directly is the way that should be handled and more reliable
As advised before, you can bind to the service. An event driven approach can be used to pass the data to the app.
i do that in B4A easily
How does B4A deal with the scenario where the app is not running? It may get around this by actually starting the app
again if it is not running (also possible with Delphi)
which in Firemonkey this is not possible or maybe possible and need hard work and developer
tweaks
It's not "hard", and there's no tweaks involved; just standard Android programming
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
|
|
|
|
Posts:
111
Registered:
8/17/17
|
|
i do that in B4A easily
How does B4A deal with the scenario where the app is not running? It may get around this by actually starting the app
again if it is not running (also possible with Delphi)
which in Firemonkey this is not possible or maybe possible and need hard work and developer
tweaks
It's not "hard", and there's no tweaks involved; just standard Android programming
--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
there is many possibilities and benefits in B4A that not normally exist in Firemonkey without tweaks that's why i migrated. beside the performance and native compatibility and the fast time development . for services in b4a every thing is in your hand without need to search here and there for the secret way .
on b4a your module can be included any where and use it any where as you like.
simply the app that i developed in firemonkey that killing me with fixes and searching took almost 3 years to create for a beginner developer like me and still the app that i made with firemonkey has great complaining issues from the client that they use specially the size and performance , other wise in b4a i created the same app from scratch in 2 weeks and i touched the big different and the most important thing its a coding friendly so developer who used to develop under delphi will not face any problem using a better and easy ide that save time and money IMHO .
i am not that perfect skilled programmer yet i faced too Manny difficulties and asked many stupid question because i wasn't really understand and were lost in delphi land without help from experts here i wouldn't understand and done any thing alone .
|
|
|
|
Legend
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|
Connect with Us