Hello everyone,
I'm new in Android development.
I'm stucked in this kind of problem: I have setup a simple application that runs an activity and a service. The service implement a simble BLE communication with a microcontroller.
I created some buttons in the activity that send the modbus command to the service; If the microcontroller's answer is good, the service sends through a broadcast the message to the activity. This part works correctly.
Now I'm trying to upgrade the app: when the activity starts, I want to automatically send few modbus command and setup some textview or switch-button based on the answer.
I did this kind of job:
during onStart() I initialize the broadcast intent.
Then I start a while loop (inside onStart) in which I send 1 modbus command through the service.
I expect the service to answer to the activity by intercepting the broadcastreceiver, and then I send the next modbus command and so on.. only when I send the last command (and so i receive the last answer) I can break the while loop and exit the onstart(). For some unknown reason I cant get this part working.
Maybe becouse the app is stucked in the while loop and so it cant pass the action to the broadcast? (i expected broadcastreceiver to works as a thread so to work simultaneously with the activity).
Maybe I have to cosider to switch to time loop thread to send these modbus command ?
Thank you everyone
Andrea
I'm new in Android development.
I'm stucked in this kind of problem: I have setup a simple application that runs an activity and a service. The service implement a simble BLE communication with a microcontroller.
I created some buttons in the activity that send the modbus command to the service; If the microcontroller's answer is good, the service sends through a broadcast the message to the activity. This part works correctly.
Now I'm trying to upgrade the app: when the activity starts, I want to automatically send few modbus command and setup some textview or switch-button based on the answer.
I did this kind of job:
during onStart() I initialize the broadcast intent.
Then I start a while loop (inside onStart) in which I send 1 modbus command through the service.
I expect the service to answer to the activity by intercepting the broadcastreceiver, and then I send the next modbus command and so on.. only when I send the last command (and so i receive the last answer) I can break the while loop and exit the onstart(). For some unknown reason I cant get this part working.
Maybe becouse the app is stucked in the while loop and so it cant pass the action to the broadcast? (i expected broadcastreceiver to works as a thread so to work simultaneously with the activity).
Maybe I have to cosider to switch to time loop thread to send these modbus command ?
Thank you everyone
Andrea