• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

BroadcastReceiver to exit a while loop in onStart()

brugne92

Lurker
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
 
Im on the other side, trying the opposite . In my situation a few of my apps that forced me to update no longer work with my android emulator. Keep in mind theyvare fre apps and the developers generate advertising dollars and a working app is beneficial for us both. I like the app and they earn money and everybody wins. I plan on decompiling the app with apktool and a key signer ptgram and try to figure it our. Not real on the top of my agenda and not sure when Ill get around to it. Actually , it just occurred to me a mismatched signature may not be a problem in a rooted android emulator.
 
Hi Javi,
i dont understand your answer.
I'm developing the app by myself with android studio, i'm not using an existent app to generate these buttons and the BLE connectivity!
 
Screenshot_2019-10-17-11-49-38.png
Hello brugne92
An app update was the cause of the incompatibility with an Andriod emulatior. I know it works on a lower version and I have a backup of it but if I downgrade the app forces me to upgread and once again does not work. I am left with two option , one unistall or two reverse engineering the app and removing forced updates. I have no formal training and am not a programmer. I have basic knowledge and familiarity with apktoolx. I also have been a root for over 5 years. I am into moding, flashing, cistom roms ,porting .....Currently running a custum rom on an old Note 4 and but I wanted fitchers of other roms and GRX system touchwize launcher. Flashing the GRX zip. ended in a soft brick I decided to flash back to stock rooted deodexed reboot and returned to custom recovery fash GRX reboot. Ising a root file manager went to /system/pri-app/ copies the GRX touchwize launcher to external sd. then deleated it from system. I then back in custum recovery dirty flashed custom rom and rebooted once again. I then repaced the touchwiz laucher that with the GRX lancher setting foulder and file permissions. I rebooted and success. No issues runs beautifully. Thats just one of many modification. Would you beleive that official Google Play Store Dark theme on Andriod 6.0.1 marshmallow? Latest version V17.0.12. To my knowledge, I have the only successful method. I posed it to XDA on October 3 2019. The real creadit got to the developers of xposed module and an app. I only found the method that by using both together bring successful dark theme on 6.0.1 MM. The main reason I even brig this up is the fact that as you are a Developer you have education that I lack. Keep in mind that Im one of the "common folk" but I have some general knowledge, I was hoping you could point me in the right direction to keep a user app from forcing an update. It just doesn't work on a newer vision. The only thing that I have that is an XDA link and will post it here. Who knows maybe be of some use to to as well. I will post back with the link as sone as I find it lol.
 
Hi Javi,
BT doesn't work in emulation. I'm testing a real system, passing a modbus string over BLE to a microcontroller, attached with a BT serial converter and waiting for an answer (the micro implements modbus too).
I've developed the classic "nordic Uart" BLE communication in the app.
My question is something more general: if i press the buton i created in the activity the modbus command is receiver by the micro, and i get th answer. IF i try to automate this exchange of string in onStart() i cant get it work. I 'm thinking there is a sort of task priority that cant get the Broadcast receiver works correctly.
By "upgrading" i mean "enabling new functionality to the app".
 
Hi Javi,
BT doesn't work in emulation. I'm testing a real system, passing a modbus string over BLE to a microcontroller, attached with a BT serial converter and waiting for an answer (the micro implements modbus too).
I've developed the classic "nordic Uart" BLE communication in the app.
My question is something more general: if i press the buton i created in the activity the modbus command is receiver by the micro, and i get th answer. IF i try to automate this exchange of string in onStart() i cant get it work. I 'm thinking there is a sort of task priority that cant get the Broadcast receiver works correctly.
By "upgrading" i mean "enabling new functionality to the app".

Thank you for responding

I am familiar and have a overall understanding as knowledge is on a basic level. However, that don't mean I can help you. Being in your shoes, I would approach this in a different direction and look for other apps that have the same function or ability to do that which you seek. Then download a few of them and test them to be sure. If yhese apps are indeed successful in tegards to what you want on your app.
The apktool and decompile the app and compare that with your app. Looking for what made theres work, code ,string, xml, files, folders.... I do this for educational purposes and has provided me a better understanding. Apktool 2.4.0 for pc. For me as a rooted user I use ApkToolx. The link for pc . The screenshots are if of app Apktoolx will provide an example.
As for me, its just a streaming apk installed and working on my laptop android emulator untill an update broke compatibility. Not very important as cast/mirror/tether with my cell phone is the simplest solution and an app I seldom use. Its not the app itself but the learning process and a feeling of accomplishment.
 

Attachments

  • 1.png
    1.png
    400.5 KB · Views: 125
  • 2.png
    2.png
    654.9 KB · Views: 94
  • 3.png
    3.png
    612.4 KB · Views: 99
Last edited:
Back
Top Bottom