Multiple tasks

FFMan

Member
Licensed User
Longtime User
I've aiming to convert/refactor a GPS based project that I developed to run using ZBasic on a Atmel 128a1 cpu, to run under Android.

A key feature of the project is that it uses 2 tasks, one to decode 10hz gps (that will arrive bluetooth under android) and one to do the user interface and gps processing items such as sector detection and display updating etc.

Is there a way on B4a the same can effectively be achieved i.e. a continuous task to accept and decode gps data, and make it available via global variables and semaphore control to another process ?
 

KY Leng

Active Member
Licensed User
Longtime User
wake up phone with BT

You should use AsyncStreams for the bluetooth connection. This will allow you to handle the communication in the background. The event is raised in the main thread.

I use AsyncStreams with Serial library to connect two BT together. However, when the phone's screen is off or when the phone get a call, the Main thread just stop, not working anymore.

Do we have the way to raise an even like play sound when we get some speciall parthem using BT when the phone is sleep?
 
Last edited:
Upvote 0

FFMan

Member
Licensed User
Longtime User
i lock my task to foreground and will turn off gsm comms for my app so getting a call not a problem for me.

i am using the phone much more like a mobile computer
 
Upvote 0

KY Leng

Active Member
Licensed User
Longtime User
AsyncStream + Service

You should use AsyncStreams for the bluetooth connection. This will allow you to handle the communication in the background. The event is raised in the main thread.

By using the service with AsyncStream, I can make my serial application to work in background without interfear with the phone call or sleep mode.
:BangHead:However, we have problem when the BT connection is lose, we cannot reconnect again if BT is working on the activity and Asyncstream work on Service module.

I also attach the code for some of you who may interest and continue further development on it.
 

Attachments

  • Test Serial-V03.zip
    2.3 KB · Views: 198
Upvote 0

KY Leng

Active Member
Licensed User
Longtime User
There is no difference between using an activity or a service. The issue is somewhere else. Which error do you get?

:sign0013: I don't understand with what you said "No different" because it was you that said if we want the application running on background, we should use service. But serial is not work in service, only AStream work.

Anyways, if I keep both Serial and AStream on Activity (I like this way than saparate them), could you please tell me how to get Data from Serial with AStream when the phone is sleeping, or busy with call ?

Best regards.
 
Upvote 0
Top