0

I have an application which connects to a BLE emergency button and reacts to an alarm the button is sending. (e.g. making a HTTP-request) The application starts a scan by clicking on a button and shows the results in a listview. After clicking on an item of the listview the application connects to the selected device (button).

The problem is that I don't know how I should run the rest of the app in background.

I found this article and came to the conclusion that a foregroundservice would make sense. The notification could show if the device is connected or not.

My question is if my conclusion makes sense or if I should use something else and if yes what.

Rene
  • 74
  • 7

2 Answers2

0

If you want your application to keep running a piece of code to run in background even if application is closed using service is the best option but however in some devices services are automatically killed if application is closed by an user. If you only want to run a code while application is running you can easily make a async class and run your desired code in background

Mr. Patel
  • 1,379
  • 8
  • 21
0

The BLE of Android always has some strange problems which are still unsolved now. I remind you that the BLE APIs cannot always work out for all brands of cellphones when you put BLE works in service of Android.

This link will tell you that you would better use BLE APIs on UI thread which will do better for more brands of cellphones.

onServicesDiscovered never called while connecting to GATT Server

Ansersion
  • 62
  • 8