I have a working app that receives Bluetooth-lowenergy notifications and responds by sending data back to the source in an async thread. I noticed under Android 8 the app is suspended along with the data send when pushed to the background. Can this be turned off or do I need to revamp the app as a Service and will the app continue to receive Bluetooth callbacks like Characteristic Changed notifications?
Update 1. I'm not able to get a real device running Oreo to test the background sleep so I created a virtual Pixel 2 running 8.1 and ran the following code in onCreate(). Surprisingly the background thread keept running on time even after opening the phone and browser apps.
Thread workThread = new Thread(new Runnable()
{
public void run()
{
int i = 0;
try
{
while (true)
{
Log.d(LOGTAG, "Work Thread: " + i++);
Thread.sleep(500);
}
}
catch (InterruptedException ie)
{
Log.d(LOGTAG, "Work Thread interrupted");
}
catch(Exception e)
{
Log.d(LOGTAG, "Work Thread error: " + e.toString());
}
Log.d(LOGTAG, "Work thread stopped");
}
});
workThread.start();