Office Hours — Today, February 3

Yesterday, February 2

Feb 3
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:20 AM
Bart
has entered the room
Bart
Hello
Mark M.
hello, Bart!
(wish this chat would signal when people enter the room...)
how can I help you today?
Bart
first off, i'm a total beginner when it comes to android and your book has been very useful :)
Mark M.
glad that it's helping!
9:25 AM
Bart
i'm following the tutorials and i'm kinda stuck at the end of chapter 14
Mark M.
do you mean Tutorial 14?
Bart
i think the editor fragment is taking up all the space; the action bar is not showing
ah yes, tutorial 14
Mark M.
well, the action bar, in terms of whether it exists or not, is driven by the activity
if your activity element in the manifest looks like <activity android:name="NoteActivity"></activity>, then the action bar should show up just fine
could you take a screenshot of your device/emulator, then upload it into the chat (there is an "Upload a file" link on the right)
Yaniv S.
has entered the room
Mark M.
hello, Yaniv!
9:30 AM
Mark M.
Bart: let me take a question from Yaniv, while you get the screenshot, and I will come back to you in a bit
Yaniv S.
Hello!
Mark M.
Yaniv: your turn! do you have a question?
Bart
alright
Yaniv S.
View paste
yes. thank you. 
So as a beginner in android I need some advice .
I have an android based device which has serial (RS232) connection
View paste
I need to create a service that:
1. receives and transmits data through the serial connection
2. receives and transmits data through the network
Mark M.
the Android SDK has no specific support for serial connections
Yaniv S.
3. receives GPS data
I know.
Mark M.
you would have to ask your device manufacturer what the programming model is for that
Yaniv S.
I gathered special API's which I found online and managed to do so
my question is this :
when I create the service , in the onStartCommand , can I run multiple threads ? where each thread manages different connection?
Bart
Mark, to be clear, you want me to take a screenshot on my phone (im testing on my device)? because there's not much to see; everything's white
Mark M.
sure
Bart
Mark M.
Bart: that is what I wanted to see -- I'll be back with you on it in a bit
9:35 AM
Mark M.
Yaniv: you are welcome to fork threads, either individually or via some manager (e.g., ThreadPoolExecutor)
you will be responsible for shutting down those threads when they are no longer needed
and, in particular, not leaking those threads when the service is destroyed
Bart
alright
Mark M.
Yaniv: whether the special APIs from your manufacturer support multi-threaded access, I cannot say
Yaniv S.
my intention is that this service will automatically start on BOOT and restart if destroyed
ok thanks. another question :
lets say my service is up and running on the device
Mark M.
Yaniv: let me follow-up with Bart first, then I will come back to you
Yaniv S.
ok .
Mark M.
Bart: somebody definitely ate your action bar
I'm not quite sure how this is happening
have you compared your code with the "answers" up at the GitHub repo?
Bart
i can pastebin relevant parts of the code if you want
yes
but maybe not good enough
Mark M.
the action bar is showing up on the main EmPubLiteActivity correctly?
Bart
yes, with the "edit note" icon
and it just disappears when i press that
Mark M.
if you could pastebin your NoteActivity and your manifest, that might give me some clues
another thing you can always do is download and run the "answers" for Tutorial 14
9:40 AM
Mark M.
if that gives you the same result, then either there's some bug in the tutorial that you're tripping over that I haven't seen, or there's something funky with your test environment
Bart
ok let me do that first
Mark M.
if, OTOH, the project in GitHub works as the tutorial instructions state, then we know that the issue lies somewhere in your project
I'll take Yaniv's next question and will come back to you in a bit
Yaniv: OK, go ahead with your next question
Yaniv S.
View paste
ok so what my main goal is to have the service up and running on BOOT , and always run and restart if destroyed. 
I managed to do so . but let's say I want to pop up a dialog fragment whenever a certain message is received in the service(via serial)
how do I do that if I have no activity? how do I pop up my own custom dialog to the user ?
Mark M.
you need an activity
it could be a dialog-themed activity, so it looks like a dialog
9:45 AM
Yaniv S.
oh.. ok
Mark M.
bear in mind that the user may not necessarily appreciate a dialog popping up in the middle of whatever the user is doing
it is possible that your proposed UI flow is appropriate for your use case
however, in general mobile development, there are few places where background operations should interrupt the user
Yaniv S.
yes this is what I want . but I also want that whenever a message from the service received, the dialog pops up on top of the previous dialog if there was already was one.
Mark M.
that is rather user-hostile
Yaniv S.
can this be acheived ?
Mark M.
a better UX would be to update the existing dialog to reflect any new information
Yaniv S.
oh..yes that better
update :)
so how can this be done ?
Mark M.
I'd use an event bus (e.g., greenrobot's EventBus)
Bart
ok, your github version works. I'm gonna compare it to my version now :)
Mark M.
when the conditions occur when the dialog is needed, the service raises an event on the bus saying "hey, update the UI!"
if the service determines that nobody picked up that message, that would indicate that you do not have a UI at the moment, and the service launches the dialog-themed activity
9:50 AM
Mark M.
Bart: OK -- I'd focus on what's in NoteActivity and your manifest
Yaniv: you can see that sort of pattern in samples like https://github.com/commonsguy/cw-omnibus/tree/m... from my book
Yaniv S.
sounds like exactly what I need , where can I read how to do that?
Mark M.
in that case, I either update the existing UI or raise a Notification, as that would be more common in mobile devices
in your case, you would replace the raise-the-Notification stuff with starting your activity
I have a chapter in the book on event buses which walks through that example, plus equivalent examples using LocalBroadcastManager and Square's Otto (two other event bus implementations)
Yaniv S.
which chapter in your book discussed this?
(wow you are a fast typer)
Mark M.
"Event Buses Alternatives"
(which is a really ugly chapter title, now that I think about it...)
page 1591 of the Version 6.4 PDF
Yaniv S.
View paste
thank you . 
I have another question if you don't mind..
Mark M.
Bart: if you encounter anything of note or have a question on your comparison, chime in
Yaniv: go ahead, though the chat hour is nearly over, so make it fast :-)
9:55 AM
Yaniv S.
ok .
so let's say I have the service running in the device's background
and it receives information through the serial connection in the service
now lets say I have different applications which I will write
UI applications
and these apps will use the information received from the service (which is a different app)
how can I communicate and pass that info?
Mark M.
:: shrug ::
it would depend upon the nature of "that info"
Yaniv S.
each message contains two int's and a string
Mark M.
and how "these apps will use the information"
if these are events, consider using broadcast Intents
if these are pulled from the clients, rather than pushed via the service, you could use a service with AIDL (ick) or a ContentProvider
Yaniv S.
yes, they are pulled from clients
So either AIDL or content provider will work
Mark M.
meaning that the clients are polling the service for updates?
Yaniv S.
?
Bart
Mark, I've literally copy+pasted your manifest and noteactivity code and no actionbar so far
but i guess i'll narrow it down eventually
thanks, maybe next time I'll have more interesting questions :p
Mark M.
Bart: I would not expect the fragment itself to have an impact, but NoteFragment would be the next place to experiment
10:00 AM
Yaniv S.
yes , well, the information is supposed to be concealed basically but I need different apps (which I will write) to be able to use that information
I hope it's not too confusing
Mark M.
Yaniv: if this is event-driven, focus on broadcast Intents or maybe a ContentProvider (so you can leverage ContentObserver)
Yaniv S.
View paste
a service in the background receives info all the time . 
-> apps that can use that indo
info
Mark M.
if this is purely on-demand from the client, you would need to use service binding or a ContentProvider
Yaniv S.
yes Iv'e read about service binding and Content provider but coudn't decide which will work for me
Mark M.
well, either could, in all likelihood
Yaniv S.
you say they will both work for my purposes?
Mark M.
again, it depends a lot upon the nature of the apps and the communications
which is well outside the scope of one of these chats
particularly one that ended a couple of minutes ago :-)
that's a wrap for today's chat
Yaniv S.
is this chat saved
?
Mark M.
the transcript will be posted to http://commonsware.com/office-hours/ shortly
Yaniv S.
thanks !!
you helped me alot
Mark M.
the next chat is Thursday, 4pm US Eastern
have a pleasant day!
Bart
likewise
Yaniv S.
ty
Bart
has left the room
Yaniv S.
has left the room
Mark M.
turned off guest access

Yesterday, February 2

 

Office Hours

People in this transcript

  • Bart
  • Mark Murphy
  • Yaniv Sheinfeld

Files in this transcript