Office Hours — Today, November 16

Yesterday, November 15

Nov 16
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Steve S.
has entered the room
Mark M.
hello, Steve!
Steve S.
Hi Mark!
Mark M.
how can I help you today?
Steve S.
Let me paste in my question:
My app requires Bluetooth communication the entire time it runs. I'm thinking of implementing it as a started service and starting the service in an Application subclass. Is that reasonable? (Note that in our application we provide the Android devices, which all run 4.4.4.)
Mark M.
what do you mean by "the entire time it runs"?
Steve S.
I mean from the time the is first started until it's shutdown (if it's shutdown)
*the app
Mark M.
um, that didn't help
do you mean "the entire time the UI is in the foreground?", "the entire time the process is running?", "until Ft. Lauderdale freezes over?", or something else
7:30 PM
Steve S.
Multiple activities of the app require Bluetooth, so I would like Bluetooth to be available to every activity in the app
Mark M.
and if the user navigates away (HOME, RECENTS, etc.)... what then?
Steve S.
This is a kiosk app, so there shouldn't be any navigation away in normal circumstances. But even if there were navigation away, it would be best if incoming Bluetooth messages kept getting received
Mark M.
OK
then the started service seems reasonable
Steve S.
ok
And starting it in onCreate of the Application subclass is a reasonable place to start it?
Mark M.
in a kiosk situation, starting from Application is probably OK, though you could perhaps get by with just doing that in onCreate() of your launcher activity
Steve S.
ok
I have another question:
View paste
I am wondering if it's a best practice to write Bluetooth data on the UI thread. The Google example and all other examples I've seen (which are all based on the Google example) do that. Do you have any ideas about whether it's ok to do that?
Mark M.
seriously? Google shows that?
all I/O on the main application thread is a bad idea
I would write on a background thread
Steve S.
ok
ok
I was thinking that was probably the case, but wasn't sure because of the example
7:35 PM
Steve S.
By the way, the Google example is called BluetoothChat
ok, no more questions today
Thank you so much! I appreciate your guidance.
Mark M.
FWIW, it seems like BluetoothChat is using background threads
looks like the I/O is being done by these ConnectedThread instances
Steve S.
But not for writing, as far I can tell
Yes, but not in the run() method.
Maybe I'm not understanding.
Mark M.
ah
yeah, that's probably just a bug
this example is as old as the hills
(I think the 2014 copyright date lies)
Steve S.
it's the only example I've ever been able to find
Mark M.
yeah, maybe in 2017, I'll get around to writing about Bluetooth
er, 2018
Steve S.
and everybody else who has an example that I've found has based it on BluetoothChat, perpetuating that bug
Mark M.
groovy
ah well, no rest for the weary, and all that
Steve S.
it would be great if you could write about it
Mark M.
it's on one of my many lists
Steve S.
i have a rewritten version of BluetoothChat that does the write off the main thread, so i'll stick with that then
7:40 PM
Mark M.
sounds like a plan
Steve S.
i'm going to post a comment to a Stackoverflow post about this issue. Would it be ok if i mention your view (with proper attribution)?
Mark M.
sure
Steve S.
thanks so much
Mark M.
you're very welcome!
Steve S.
you've solved all my problems today!
Mark M.
that seems a bit over the top
Steve S.
well, maybe a little...
have a great rest of the day
Mark M.
you too!
Steve S.
has left the room
8:25 PM
Mark M.
turned off guest access

Yesterday, November 15

 

Office Hours

People in this transcript

  • Mark Murphy
  • Steve S