Get bluetooth serial to listen in the background

lightay

Member
Licensed User
Longtime User
Dear Basic4Android experts,

I downloaded the bluetooth serial sample and got it working without doing much. My app will perform some action when certain pattern is received on the serial link.

http://www.b4x.com/forum/basic4android-getting-started-tutorials/6908-android-serial-tutorial.html

However, I want the bluetooth serial link to be listening for the pattern even when the app is in the background. The problem I face is that the app stops listening when it is moved into the background. Is it possible to get the app to continue listening even when it is in the background for Basic4Android?

Thank you.
 
Last edited:

lightay

Member
Licensed User
Longtime User
You should use a service for that. You will need to call Service.StartForeground to prevent Android from killing the service.

Thanks for the tip.

Is there any sample tutorial or source code that I can refer to for Service.StartForeground?

Thank you for your help.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I tried to put the bluetooth admin and everything in a service, and failed miserably. Well, the progressdialogs and stuff dont show inside the service.
 
Upvote 0
Top