0

I'm currently making an app to exchange data between phone and a bluetooth device. I need this exchange to be in the background so when the device send some data, the app can read it and act from it, whenever the app is active or not.

I already establish some read and write data in the app, but only when it is active for the user. Now I want to take the next level and make the same read and write data but in the background, so the connection between the devices is establish and maintain.

I already know about jobschedule and service. Also, I know that, with the new versions of Android OS, services are killed by some time passed or in Doze mode. Other things I found out was to use threads in the background, but I'm still searching for that. But in the end, I'm still a newbie and maybe I'm missing out some information or I couldn't understand the concepts in their fullness, because I can't see yet how to make a process in background that could react upon a message received from the device or react upon a message received from the phone and create this exchange data.

In all, this raised me a question: how to have this kind of task in the background which read and write data from bluetooth connection between phone and a device? Is it jobschedule? Threads? Or there is one that I'm missing out?

Yet, in SO exist some questions about this related topic, some are outdate about the killing service which android does now, but if this question is a repeated one, please link me one that can solve this problem. I'll be gratefull.

Side note: I would like to know if there is a way to turn this task on and off by some condition or by the user's preference.

EDIT: Some questions I found:

  1. How to keep Bluetooth connection background? - This one is recent, but I don't know if this service will not be killed by the system.
  2. Android 8.0 background services for bluetooth device - This is recent too and it has in his answer the bluetooth connection could be killed too.
  • Can you please include the questions you are referring to? And also, any code examples too. – oxr463 Jul 18 '19 at 23:22
  • @LucasRamage Thanks for the comment! About the questions, I'll search for some I found, may take a while but I'll edit out. About the code, I can't see how it would help, but I'll try my best to do it so. – Filipe Varela Jul 19 '19 at 00:18

0 Answers0