Android Question How to handle.. service running while activity ended

Arf

Well-Known Member
Licensed User
Longtime User
The thread title is a bit undescriptive because I could not come up with the right words.

So my app runs a service to deal with bluetooth comms, it's quite a complex serive but works well. However, leave my app and open SETTINGS->BLUETOOTH, this new settings activity automatically starts a bluetooth scan, which means that the DeviceFound function in my service module gets hit when a device is found. Since the scan was not started from my service, this creates problems.

Similarly, if I turn bluetooth off in SETTINGS->BLUETOOTH or by any other means, Serial1_Connected in my service module gets hit unexpectedly and that causes problems.

I am just trying to figure out what the best way to deal with this might be:

1: Kill the service when my app goes in the background (I think I read that this is discouraged)

2: Somehow detect if my app is in the background when these functions are hit, and exit the functions without doing anything if this is the case. How could I detect that though?

3: Something else

Thanks
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Somehow detect if my app is in the background when these functions are hit, and exit the functions without doing anything if this is the case. How could I detect that though?
B4X:
If isPaused("ActivityName") then
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…