? Limit to how many Services a Service can start

Azhar

Active Member
Licensed User
Longtime User
Hi

Just a quick question. My application suddenly doesn't work and I have no idea.
The Main activity will upon pause, call a 'serviceBoot' service.
The serviceBoot service will set up a load of other services at specific times for the current day. There were about seven of them. It used to work and now the phone(s) tested on only show the serviceBoot service loaded and of course the Main process.

I've checked in the Background Process Limit of the Android Developer Options on each phone and this is set to Standard.

In the SDK, do you have to download the API's for every model phone that your application is to run on? This is my only thought left.
I have gone from 2.2.2 to 4.0.3 via rooting with ICS on my phone but this doesn't work on a straight 4.0.3 phone. I did initially develop this application on the 2.2 (API8) though if that makes a difference.

Much appreciated for any replies.

Azhar
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
In the SDK, do you have to download the API's for every model phone that your application is to run on? This is my only thought left.
No. Actually it doesn't matter which SDK you are compiling with (except if you are using features not available in older versions).

How is the serviceBoot implemented?
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Hi

Thanks for that.

The serviceBoot is marked as 'Start at Boot. This is fine - loads okay.
Within this service module, the Service_Create just loads a user settings file.
In Service_Start, it will check for a new day (entered midnight) at the top then if true, recalculate some things calling via callSub(Main...) some subroutines.

Then basically it will set about seven StartServiceAt(serviceName, Time, True) at specific calculated times according to the user settings file amongst other things. This does all check out fine.

Now I may be on the wrong train of thought here. If a StartServiceAt is setup to say a future time of the current day (or next day) and the time now hasn't reached that set time, will that service name show in the android application log as active? Or does it only show when Android actually processes the future service when the time now = that set time?

Should I StopService(ServiceName) immediately after the ServiceName does it's job (when time now = specific StartServiceAt time?

A typical StartServiceAt setup is as follows taken from the Service_Start sub of serviceBoot:

'for sunrise Time
alarmHours = s.Val(s.Left(Main.sunrise,2)) : alarmMins = s.Val(s.Right(Main.sunrise,2))
Dim sunriseAlarmTime As Long
sunriseAlarmTime = today + alarmHours * DateTime.TicksPerHour + alarmMins * DateTime.TicksPerMinute
If sunriseAlarmTime < DateTime.Now Then sunriseAlarmTime = DateTime.Add(sunriseAlarmTime, 0, 0, 1)
Log("Sunrise Date is " & DateTime.Date(sunriseAlarmTime) & " Sunrise Time is " & DateTime.Time(sunriseAlarmTime))
StartServiceAt(sunriseAlarm, sunriseAlarmTime, True)


Just don't know why these StartServiceAt's aren't activating.

Thanks,

Azhar
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Ah I see now that I was seeing the ServiceStartAt differently.

They will only show up in the running services log in Android when started. I thought they would show rather like an alarm time waiting to go off.

So my problem may reside in the audio library within each of the called services.

Azhar
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
This is very strange:

Dim today As Long
today = DateTime.DateParse(DateTime.Date(DateTime.Now)) 'Sets today at 12:00 AM
'=======================================================================================================
'this is a test service
alarmHours = 8 : alarmMins = 41
Dim testAlarmTime As Long
testAlarmTime = today + alarmHours * DateTime.TicksPerHour + alarmMins * DateTime.TicksPerMinute
If testAlarmTime < DateTime.Now Then testAlarmTime = DateTime.Add(testAlarmTime, 0, 0, 1)
Log("Test Date is " & DateTime.Date(testAlarmTime) & " Test Time is " & DateTime.Time(testAlarmTime))
'StartServiceAt(myTestAlarm, testAlarmTime, True)
StartService(myTestAlarm)
'=======================================================================================================

This was called from the Service_Start of service 'serviceBoot

I fixed the alarm time to static variables: 8:41

Upon the Main activity going into Pause and thus starting service serviceBoot,
the StartServiceAt won't start (disregard the rem ')
but StartService will work as son as the serviceBoot starts as expected.

So how come none of my StartServiceAt's won't work? They always used to.

Azhar
 
Upvote 0

Azhar

Active Member
Licensed User
Longtime User
Do you call StartServiceAt and it doesn't start the service on the scheduled time? Make sure that you are not calling StartServiceAt again for the same service as it will cancel the previous one.

Thanks for that.
All sorted now. It does all work again.

Azhar
 
Upvote 0
Top