Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TTimer Delphi Tokyo 10.2.1



Permlink Replies: 8 - Last Post: Apr 2, 2018 8:36 PM Last Post By: Dave Nottage
D Robinson

Posts: 7
Registered: 11/2/99
TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2017 8:13 PM
I have found that the TTimer fires in windows (Version Creators Update fully patched). The same routine when run on an Andoid 6.0 Device (Nexus 7, 2013) does not fire the timer. This also fails on an LG G6 -- android 7 device.

This is in Delphi 10.2.1 i.e the latest version.

Does anyone else have issues with the Timer device on Android.?

This is the actual routine.

procedure TfrmAudioNote.Timer1Timer(Sender: TObject);
begin
if (MediaPlayer1.Media <> nil) and
(MediaPlayer1.CurrentTime = MediaPlayer1.Duration) then
begin

btnPlayPause.Enabled:=false;
btnPlay.Enabled := true;

MediaPlayer1.Stop;
MediaPlayer1.CurrentTime:=0;
end;
end;
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 12, 2017 9:35 PM   in response to: D Robinson in response to: D Robinson
D Robinson wrote:

Does anyone else have issues with the Timer device on Android.?

I'm not. Just did a simple test app that contains a timer on the form, Enabled set to True, an Interval of 1000, which
updates the time on a label - works fine. (Nexus 5X, Android 7.1.2)

This is the actual routine.

That's the handler for the timer. It's more important to know how you've set up the timer.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
D Robinson

Posts: 7
Registered: 11/2/99
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 10:22 AM   in response to: Dave Nottage in response to: Dave Nottage
Thanks, I will investigate further. Perhaps it is the audio component itself working differently on Android.

Dave Nottage wrote:
D Robinson wrote:

Does anyone else have issues with the Timer device on Android.?

I'm not. Just did a simple test app that contains a timer on the form, Enabled set to True, an Interval of 1000, which
updates the time on a label - works fine. (Nexus 5X, Android 7.1.2)

This is the actual routine.

That's the handler for the timer. It's more important to know how you've set up the timer.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

Edited by: D Robinson on Aug 14, 2017 10:22 AM
D Robinson

Posts: 7
Registered: 11/2/99
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 2:50 PM   in response to: D Robinson in response to: D Robinson
Figured it out it's a bit of an interaction problem -- looks like a compiler or component bug. Will try to post to QC if I can remember where it is.

D Robinson wrote:
Thanks, I will investigate further. Perhaps it is the audio component itself working differently on Android.

Dave Nottage wrote:
D Robinson wrote:

Does anyone else have issues with the Timer device on Android.?

I'm not. Just did a simple test app that contains a timer on the form, Enabled set to True, an Interval of 1000, which
updates the time on a label - works fine. (Nexus 5X, Android 7.1.2)

This is the actual routine.

That's the handler for the timer. It's more important to know how you've set up the timer.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com

Edited by: D Robinson on Aug 14, 2017 10:22 AM
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 14, 2017 2:58 PM   in response to: D Robinson in response to: D Robinson
D Robinson wrote:

Figured it out it's a bit of an interaction problem -- looks like a compiler or component bug. Will try to post to QC
if I can remember where it is.

Bug with which component, or what compiler issue?

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Rudy Velthuis (...


Posts: 7,731
Registered: 9/22/99
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 16, 2017 4:27 AM   in response to: D Robinson in response to: D Robinson
D Robinson wrote:

Figured it out it's a bit of an interaction problem -- looks like a
compiler or component bug. Will try to post to QC if I can remember
where it is.

QC is offline, by now. Use Embarcadero's Quality Portal instead. That
is the current bug reporting system.

https://quality.embarcadero.com/

--
Rudy Velthuis http://www.rvelthuis.de

"Haste is of the devil. Slowness is of God." -- H L Mencken
aneal chandra

Posts: 6
Registered: 4/15/01
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 20, 2017 11:38 PM   in response to: D Robinson in response to: D Robinson
I am also seeing problems, with a TTimer firing every 1 second and updating a label. The problem is reproduced by locking the screen and leaving the app running for, for example, 5 minutes. When you unlock the screen the app is unresponsive and the label is frozen. Sometimes the app comes back to life after a minute or so. This problem does not occur on iOS

I am moving away from the TTimer as this post suggests https://stackoverflow.com/questions/34245482/embarcadero-delphi-xe10-android-service-with-a-timer
Joaquin Pardo

Posts: 9
Registered: 3/17/06
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 7:49 AM   in response to: aneal chandra in response to: aneal chandra
aneal chandra wrote:
I am also seeing problems, with a TTimer firing every 1 second and updating a label. The problem is reproduced by locking the screen and leaving the app running for, for example, 5 minutes. When you unlock the screen the app is unresponsive and the label is frozen. Sometimes the app comes back to life after a minute or so. This problem does not occur on iOS

I am moving away from the TTimer as this post suggests https://stackoverflow.com/questions/34245482/embarcadero-delphi-xe10-android-service-with-a-timer

Excuse me but it DOES NOT work, it does not respect the times, it does in long times and sometimes it does not work either, leaving hours without working.

I'm going to post my example, so you can see:

This problem has not been solved by jetty for too long.

function TDM.AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
var atask : Itask;
Notificacion : TNotification;
begin
atask := Ttask.create(procedure()
var
hacer: boolean;
ahora : Tdatetime;
begin
hacer := false;
REPEAT
begin
ahora := now;
Notificacion := NotificationCenter.CreateNotification;
Notificacion.Name := 'Notificando';
Notificacion.Title := DateTimeToStr(ahora);
Notificacion.AlertBody:= DateTimeToStr(ahora);
NotificationCenter.PresentNotification(Notificacion);
Notificacion.Free;
sleep(60000);
end;
UNTIL hacer = true;;
end);

atask.Start;
end;

Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: TTimer Delphi Tokyo 10.2.1
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 8:36 PM   in response to: Joaquin Pardo in response to: Joaquin Pardo
Excuse me but it DOES NOT work, it does not respect the times, it does in long times and sometimes it does not work either, leaving hours without working.

I'm going to post my example, so you can see:

This problem has not been solved by jetty for too long.

function TDM.AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
var atask : Itask;
Notificacion : TNotification;
begin
atask := Ttask.create(procedure()
var
hacer: boolean;
ahora : Tdatetime;
begin
hacer := false;
REPEAT
begin
ahora := now;
Notificacion := NotificationCenter.CreateNotification;
Notificacion.Name := 'Notificando';
Notificacion.Title := DateTimeToStr(ahora);
Notificacion.AlertBody:= DateTimeToStr(ahora);
NotificationCenter.PresentNotification(Notificacion);
Notificacion.Free;
sleep(60000);
end;
UNTIL hacer = true;;
end);

atask.Start;
end;

"it does not respect the times, it does in long times and sometimes it does not work either, leaving hours without working.."

That's not necessarily an Embarcadero issue.

If you want to run some code at certain intervals in a service, you really should be using AlarmManager. On Android 6 and greater, if the device has been in lock screen mode for a while ("doze" mode), your code will not run unless you have set an alarm using setAndAllowWhileIdle or setExactAndAllowWhileIdle. In order to respond to the alarm, you need to use a broadcast receiver that is written in Java, that will call startService on your service when the alarm is triggered.

A while ago I created this demo for starting a service at a scheduled time:

https://github.com/DelphiWorlds/KastriFree/tree/master/Demos/ScheduledService

It could be modified to start the service at regular intervals, however it would also need to be modified to use setExactAndAllowWhileIdle so that on Android 6 and greater the service will start while in "doze" mode. If I have time, I'll update the demo to do just that.

--
Dave Nottage [TeamB]
Find hints tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02