Android Question How a simple pnl.invalidate can speed up a process?

Marcob

Member
Licensed User
Longtime User
I stumbled in this very odd behaviour of my app and I hope someone could give me a clue of what is happening.
After a lot of tests it seems that just adding a dummy pnl.invalidate instruction could speed up the process by about 20%.

The setup...
The app is essentially composed by an activity and a foreground service. The service runs a dedicated thread wherein an endless loop gets data from the USB interface. The activity starts the service and, using a 100 ms timer, displays some parameters according to the received data.
At the other end of the USB link a microcontroller transmits a data packet.
As the USB connection uses hardware handshaking and the tx speed of the uC is far higher than the actual reception rate, the duration of the transmitted packet will be essentially determined by the speed of the endless loop inside the thread.

The results...
If the activity is closed, the tranfer rate decreases by about 20%! I would expect the opposite... a very strange behaviour...

Playing with activity, it turns out that if the 100 ms timer subroutine is just simply the following:

B4X:
Sub Timer_Tick()
  pnl.invalidate 'where pnl is any one of the defined panels of the activity
end sub

the transfer rate increases compared to the case where the activity is closed.
If the pnl.invalidate line is commented, the transfer rate slows down to the same value you get with the service only (activity closed).

Conclusions...
1) Why pnl.invalidate is able to speed up the endless loop of a thread?
2) As I need the maximum speed also when the activity is closed, how could I emulate the "pnl.invalidate" effect when only the service is running?

If you have any hints or clues to provide I will be happy to test it in my setup.
Thank you.
 
Top