Android Question StartServiceAtExact not firing in release not connected mode

echapeta

Member
Licensed User
Longtime User
Hello,

I have an app that must wake up at a precise interval of 20 secs.

We are using StartServiceAtExact, but when running in a real device, not emulator, in RELEASE mode, and NOT CONNECTED to the B4A environment by USB, after about 3 times firing ok, it doesn't fire.

When running DEBUG mode or in RELEASE mode and connected to the B4A environment by USB always runs ok.

Where could be the difference or the problem ?

Thank You.
 

echapeta

Member
Licensed User
Longtime User
Hello Erel,

I already tried, but the testing device runs sdk 22, then it ends in the StartServiceAtExact call.

Is annoying not having a way to trigger something at a precise time.....


Thank You
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

Yes, after a random time it finally fires.

Sometimes, several seconds or minutes after waking up the phone manually.

This is odd, because the phone is not sleeping.

Could you help me to find a way to wake up at precise times ?

For instance like the clock alarms, they always fire properly....



By the way, checking the code I found at the service Process Globals variables declared twice without any warning from the IDE.
It seems they came when I ported the project from an earlier version.
The IDE checks duplicated declarations just when you modify a line ?


Thank You.
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Here you have a trace, the service is running in foreground mode;

** Service (starter) Start **
13.24.14 : ========= Service Starts: / Bundle[{android.intent.extra.ALARM_TARGET_TIME=1475598254060, android.intent.extra.ALARM_COUNT=1}]
13.24.14 : Target Time = 13.24.14
13.24.14 : //// Start at: 13.24.34
** Service (starter) Start **
13.24.34 : ========= Service Starts: / Bundle[{android.intent.extra.ALARM_TARGET_TIME=1475598274084, android.intent.extra.ALARM_COUNT=1}]
13.24.34 : Target Time = 13.24.34
13.24.34 : //// Start at: 13.24.54
** Activity (whereami) Pause, UserClosed = false **
13.24.43 : Screen Off
** Service (starter) Start **
13.24.54 : ========= Service Starts: / Bundle[{android.intent.extra.ALARM_TARGET_TIME=1475598294226, android.intent.extra.ALARM_COUNT=1}]
13.24.54 : Target Time = 13.24.54
13.24.54 : //// Start at: 13.25.14
** Service (starter) Start **
13.26.02 : ========= Service Starts: / Bundle[{android.intent.extra.ALARM_TARGET_TIME=1475598314379, android.intent.extra.ALARM_COUNT=1}]
13.26.02 : Target Time = 13.25.14
13.26.02 : //// Start at: 13.26.22
** Activity (whereami) Resume **
13.28.44 : User Present
13.28.44 : User Present
** Activity (whereami) Pause, UserClosed = false **
13.29.17 : Screen Off
** Activity (whereami) Resume **
13.29.26 : User Present
13.29.26 : User Present
** Activity (whereami) Pause, UserClosed = false **
13.29.57 : Screen Off
** Activity (whereami) Resume **
** Activity (whereami) Pause, UserClosed = true **
** Activity (main) Resume **
Object context is paused. Ignoring CallSubDelayed: JobDone
** Activity (main) Pause, UserClosed = false **
** Activity (whereami) Create, isFirst = false **
** Activity (whereami) Resume **
** Activity (whereami) Pause, UserClosed = false **
13.30.33 : Screen Off
Object context is paused. Ignoring CallSubDelayed: JobDone
** Service (starter) Start **
13.31.02 : ========= Service Starts: / Bundle[{android.intent.extra.ALARM_TARGET_TIME=1475598382625, android.intent.extra.ALARM_COUNT=1}]
13.31.02 : Target Time = 13.26.22
13.31.02 : = Start Timer Intent Ends at 13.28.54
13.31.02 : >>>>>>>>>>>>>>>>>>> Service Watch Me Ended
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

Then, something can be done because the phone's alarms are very precise.....

How they achieve that ?

Thank You,
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

Ok, understood.

I have read in the blogs about an Alarm Clock example that comes with the SDK, but I didn't checked it.

I have tried with the combination of all the ways found in the B4A support:

StartServiceAtExact
StartServiceAt
Service.StartForeground(..)
#StartCommandReturnValue: android.app.Service.START_STICKY
Adding dummy timers firing every second
Adding timers that should fire at the same time , before or after the Service Star

So far , I found the following behavior:

1 - the delay firing is random, spanning from 1 second to 10+ minutes, when happens, the delay lasts even after you wake up the device manually (*)
2 - the delay firing increases with the lapse, ie, when you schedule to fire every 5 secs it fails less times and for less time delay than when the lapse is 20 secs

(*) this is odd, the log doesn't show that the service started, but shows entries for traces I added, In this scenario, even the timers doesn't fire

I will try scheduling a fixed short lapse, testing from 1 to 10 seconds StartServiceAt lapse, because it seems the current OS' strategy let's alone tasks firing frequently.....
 
Upvote 0

echapeta

Member
Licensed User
Longtime User
Dear Erel,

For the record, the less ugly workaround in the current scenario is:

set the service to foreground
set the service as sticky
Set a continuous cycle of startserviceat every 10 secs or less
inside the service start keep a partial lock ( after a while, 3 min, i.e.) the os doesn't let the service start complete.

let's see how far we can go with this way.....
 
Upvote 0
Top