Debigging service module does not work

corwin42

Expert
Licensed User
Longtime User
Debugging service module does not work

I'm trying to debug a service module with B4A v1.41.

My Service is started with StartService() in Main.Activity_Create(). I set a breakpoint just in the first line of Service_Create().

When I start the App, execution stops at the breakpoint. But after a few seconds execution is resumed automatically and I can't control the debugger anymore.

Debugging a simple test application with one activity works great.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not a bug. It is a limitation and it will be discussed in the 'debugging tutorial'.
Service_Create / Service_Start / Service_Destroy subs must finish in 20 seconds or you will get an ANR dialog (Application Not Responding). The debugger is set to continue running after 14 seconds to avoid this issue.
Note that if your service raises any events (with a timer or by downloading a Url with the Http library for example) then you will be able to debug these events without any limitations.

For similar reasons the debugger will not pause at all during Activity_Pause and between a call to StartService and the actual start of the service (either Service_Create or Service_Start).
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Ok, I understand.

I'm listening to some PhoneEvents in my Service (BatteryChanged, ScreenOn, ScreenOff).

When an event gets fired while step debugging its a bit strange. If I click on F8 (Step) then, the event sub of the event just received is executed until the end and every executed line is highlighted.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Yes. I listen to BatteryChangedEvent and ScreenOn Event.

Program is paused at a breakpoint in ScreenOn event sub. Then a BatteryChangedEvent fires. Then I press F8 (Step) and then the BatteryChangedEvent sub is completely executed and every executed line is highlighted. The BatteryChangedEvent fires quite often.

I noticed that when setting a breakpoint in ScreenOn event Sub I get the ANR dialog after 20 seconds. But when I press "wait" on it everything works fine from then.
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Simple Test project for the issue.

Try placing a breakpoint in AHBatteryService.PhoneEvent_ScreenOn and you will see what I'm talking about.
 

Attachments

  • BatteryMonitor.zip
    12.7 KB · Views: 349
Upvote 0
Top