Notifications for android via my iot device


Hello community.
I am creating a bluetooth app to receive a message when i push a button in my IoT device(esp32). I have the code ready on the esp32 side and when a button is pressed the message is seen in bluetooth serial monitor(3rd party app in play store) im making mine just to get message and then notify it in notifcations bar. I created an sample app were bluetooth connects/disconnects. but i want a while loop to check the messages aand display in notifcations bar. THe problem is when i add while loop the app hangs. how to check the bluetooth recived bytes at regular interval when app is in background so that notifcations are actively showing when button is pressed. my thunkable bluetooth code is as below


rather than a while loop try an if statement inside the Clock.Timer event