Office Hours — Today, August 28

Tuesday, August 26

Mark M.
has entered the room
Mark M.
turned on guest access
Aug 28
3:55 PM
Gabriele
has entered the room
Gabriele
hi :)
Mark M.
sorry about that -- accidentally clicked "Sign out"...
how can I help you today?
Gabriele
Firstly I've tried EventBus, like you told me, Mark. It's very good, I've removed a lot of code and decoupled components.
EGHDK
has entered the room
Mark M.
Gabriele: glad to hear it worked for you
Gabriele
Now I'm watching at the GUI of my IRC client, I thought to do it like this: http://postimg.org/image/6oqh40a31/
Mark M.
EGHDK: hi, I'll be with you shortly!
Gabriele
Should I use the viewpager or something like this, to implement it?
Mark M.
that is a distinct possibility
Gabriele
I thought one fragment visible by default, the channel messages and then, by swiping to open the nicklist/channels
and maybe tapping the queries?
or you have a better idea/solution? :P
Mark M.
I am not sure what "tapping the queries" means
in general, do not overload swipe gestures
Gabriele
tapping on the private message, sorry
Mark M.
so, if you want to use swiping to move to different active chat channels/private message spaces, do not also use swiping to move to the nicklist
4:00 PM
Mark M.
if you want swiping to handle the nicklist and channel list, then just use tabs for moving to the different active chat channels/private message spaces
Gabriele
this seems reasonable, yes
I let you help EGHDK, then I have another question, thank you for now :)
Mark M.
OK
EGHDK: your turn! do you have a question?
EGHDK
in my reading I've found a java tool called findbugs for Java. Is this something that's recommended for android? If not are there any other similar tools for Android?
Mark M.
I have no idea if FindBugs is usable on Android-centric Java code
the Android SDK has Lint, and that is integrated into Eclipse and Android Studio
EGHDK
So finabugs is sort of like a lint?
Mark M.
they are both static code analyzers
beyond that, since I have never used FindBugs, I cannot tell you much about it
EGHDK
But from your experience findbugs is presumably something not really necessary for Android development.
Okay got it. Thanks
Mark M.
it is definitely not really necessary
4:05 PM
Mark M.
Gabriele: back to you -- you said that you had another question?
Gabriele
Last time we talked about adding a Service, so I started reading again your book and find that there are two ways to communicate with them, startService() and binding. I've understand that one is for half-duplex communication and the other full-duplex, but I'm not able to choose which one is better for me (I think there are other things to consider). Can you help me understanding how to choose? What are the important differences I should consider?
Mark M.
"I've understand that one is for half-duplex communication and the other full-duplex" -- not really
both are intrinsically half-duplex, in that they give the client a way to tell the service what to do
binding, particularly for local services, makes it straightforward to implement a callback or listener pattern for sending data from the service to something else
however, an event bus or other techniques can fill that role with the command pattern
I'm a big fan of loosely-coupled architectures, and so I tend to go with the command pattern and an event bus
Gabriele
so I can use eventbus for the service, also?
Mark M.
sure
Gabriele
I'm liking it a lot, too
Mark M.
you can't start a service with an event, but given that the service is running, it can post events, or it can listen for events
the tutorials in the book now use an event bus to have the DownloadCheckService tell the rest of the app that a book update was downloaded and unpacked
Gabriele
I will search it and have a look, thank you, this seems a good solution
Mark M.
now, just because I lean towards the command pattern and an event bus does not mean that binding is evil
particularly with retained fragments, it's easier to manage the state complexity than it used to be
but I can't name any scenario off the top of my head where *I* would use binding over the command pattern
4:10 PM
Mark M.
let me take another question from EGHDK, and I'll be back with you in a bit
Gabriele
yes, I've understand what you mean :)
sure
Mark M.
EGHDK: your turn -- do you have another question?
EGHDK
With Eclipse I'm trying to build an app using command line. SInce Acelipse/ADT using ANT as the build system why do I need to install Ant to use cmd line to build an apk?
Mark M.
Eclipse is not using Ant as the build system
EGHDK
...?
Mark M.
that table is wrong
EGHDK
=(
Mark M.
I think they wanted to draw the contrast between Ant and Gradle, and so they shoe-horned it in there
at a high level, Android Studio and Gradle fill the same role that Eclipse and Ant do
however, while Android Studio actually uses Gradle for builds, Eclipse does not use Ant for builds
EGHDK
Got it.
So what does Eclipse actually use? Is there any way to use the build system eclipse uses in the cmd line? So that I don't have to install something else?
Mark M.
Eclipse uses Eclipse :-)
IDEs traditionally have their own build systems, rather than delegating to third-party code
EGHDK
Figures. So no cmd line option right?
Mark M.
correct
EGHDK
IDE's have their own build system. So Android Studio is the odd one out in this case?
Mark M.
that's complicated
Android Studio is based off of the IntelliJ IDEA IDE
IDEA has its own build system
4:15 PM
Mark M.
however, more so than many IDEs, it treats its own build system as just one possible build system implementation
hence, IDEA can integrate with Gradle, Maven, and maybe Ant (I forget on that one)
Android Studio by default uses Gradle
EGHDK
Got it.
Mark M.
my understanding is that there are recipes for using Maven's build system instead of Gradle with Android Studio, though they aren't officially supported
Eclipse has been moving in a direction to try to be more flexible about delegating to other build systems
so there are Maven and Gradle plugins for Eclipse
but there are limitations
which is one of the reasons Xav hemmed and hawed at Google I/O when asked about Gradle for Android support for Eclipse/ADT
let me take another question from Gabriele, and I'll be back with you in a bit
Gabriele: do you have another question?
Gabriele
Today, using EventBus, I've encountered only a "problem" (maybe my error): I've read about the convention of the suffix MainThread and so on, but to try it, I was using onEvent; I got a message saying it couldn't find any onEvent or something like this, but changing it to onEventMainThread worked. I know it's a bit generic, but maybe you know the reason of this behavior that I cannot understand.
Mark M.
onEvent() definitely works -- one of my samples uses it
in fact, you *need* to use it if you want to use the ordered-delivery feature
Gabriele
on some class it was working, but on one it said it couldn't find any onevent, or something like this
Mark M.
off the top of my head, I do not know what might have caused that
4:20 PM
Gabriele
eheh, thank you, I was just curios, if I find it I will search on google, or report you some more detailed info :)
Mark M.
OK
Julius
has entered the room
Mark M.
hello, Julius!
Julius
hey Mark, wow it's a long time since I've been here! :)
Mark M.
Julius: the others have had a couple of questions already, so... do you have a question?
Julius
(hi all)
Gabriele
hi :)
Julius
oh just wanted to pop in to say, hey and wondering if there's any chance you might look into the mergeadapter Josh made to work with erm RecylerView… I know you don't have a tardis and have a busy schedule :)
Mark M.
more to the point, I haven't looked at RecyclerView and probably won't get a chance until whatever-L-turns-into ships "for realz"
Julius
cool, yeah we're a bit concerned about changes too
Mark M.
hence, I wouldn't really grok a RecyclerView-flavored MergeAdapter
Julius
ok thanks, good to know
Mark M.
in my case, since you can't readily use it on pre-L environments, I didn't want to cover it in my book just yet
Julius
hope all is going well and thanks for the great docs. Still finding pieces in your books for things that come up like printing and so on
Mark M.
glad you like it!
Julius
it's a life saver
and good fun to read (I like the gags)
Mark M.
hmmm... Pep-O-Mint flavor? :-)
4:25 PM
Julius
:)
fruity
Mark M.
that'd be the BlackBerry chapter, then
and before this all turns into a comedy routine...
Julius
heh well we have one of our apps on Blackberry
Mark M.
EGHDK: your turn! do you have another question?
EGHDK
View paste
Reading Effective Java... can you tell if this is supposed to be sarcasm... and why? "There’s a new way to create unnecessary objects in release 1.5. It is called
autoboxing, ..."
Mark M.
I'd say that's about 80% sarcasm
Julius
(ok will leave you all thanks and have a great day; Friday already!)
EGHDK
-_-
Julius
has left the room
Mark M.
autoboxing does create objects, as that's kinda the point, converting primitives (e.g., int) into object equivalents (e.g., Integer)
and, particularly at the micro-benchmark level, using autoboxing in loops can create a lot of unnecessary objects
EGHDK
Okay. Yeah I mean I figured. Just wanted to run it by somebody quickly.
Mark M.
the tone is what makes it sarcastic -- the underlying point has merit
Gabriele: back to you! do you have another question?
Gabriele
A last question about fragments: which is the relation between setContentView and adding a fragment with FragmentManager? I can't understand why it should be a child to being added (or something like this)
Mark M.
sorry, but I do not understand your question
Gabriele
to add a fragment dinamically, I can use fragmentmanager and add it, but it should be a "child" of what I passed to setcontentview, right?
4:30 PM
Mark M.
the ID passed into the add() or replace() methods represents the container that should hold the widgets managed by the fragment
all widgets have a parent container
without a container, Android does not know where to put the widgets, how to size them, etc.
whether you use an existing container (android.R.id.content) or one of your own is up to you
Gabriele
uhm, so Android get my parent from what I've passed to setcontentview, but not necessarily?
Mark M.
again, it is up to you
some of my examples, where I am using just one fragment, I load into android.R.id.content -- the FrameLayout normally used as the container that holds onto whatever is inflated based on a setContentView() call
but, in the EU4You examples, where I am specifically demonstrating large-screen approaches, I am loading fragments into FrameLayouts inside of a horizontal LinearLayout
where the containers are set up via a call to setContentView()
Gabriele
why did you choose this approach, with larger screen size?
4:35 PM
Mark M.
the EU4You samples are demonstrating the master/detail pattern
which implies that, on a landscape tablet, you have two fragments (master, detail) side by side
Gabriele
yes
Mark M.
a LinearLayout is an easy way to accomplish that
Gabriele
ah
Mark M.
and since Android needs to know about this LinearLayout, somewhere along the line, setContentView() is involved
to flip it around, pretty much the only time you *don't* use setContentView() is if you are loading a single fragment into android.R.id.content
Gabriele
yes, now it's clear to me :)
ok Mark, thank you as always! :)
Mark M.
you are very welcome
EGHDK: back to you! do you have another question?
Gabriele
(bye all, have a good evening (think to you it's evening!))
EGHDK
So I'm coming across a lot of mutable, immutable in my books especially in effective java. But no one has actually explained it. Like this sentence confused me "An object can always be reused if it is immutable" I thought if a object WAS mutable (mutate-able?)it can be reused, because it can change?
Gabriele
has left the room
Mark M.
I do not know what that sentence means that you quoted
mutable = contents can be changed
immutable = contents cannot be changed
EGHDK
Okay. That's what I thought.
But does that mean that the object change change state or you can't change a variable to point to another object?
Mark M.
sorry, I am having difficulty parsing that sentence
4:40 PM
EGHDK
Hmm.. Okay.
Basically. The example I'm given to not ever ever do is: String s = new String("hello world");
Mark M.
it's probably pointless
let's change the code up a bit:
String s1 = "hello world";
String s2 = new String(s1);
at this point, both variables point to different objects representing the same characters
and *possibly* the same char[] that holds the characters
(that's an implementation detail of String that I do not recall off the top of my head)
but since you cannot change the char[] array inside of a String directly, that is why they say that String is immutable
4:45 PM
Mark M.
if you have another question, go right ahead
4:50 PM
EGHDK
Yeah sorry network issues. Am I still live?
Mark M.
yes, you're here now
EGHDK
Okay yeah. Last question. Especially since we talked about this before.
"If an activity is paused or stopped, the system can drop it from memory either by asking it to finish (calling its finish() method), or simply killing its process. When the activity is opened again (after being finished or killed), it must be created all over."
4:55 PM
EGHDK
The system will never kill an activity though right? It will only kill the process or nothing?
Mark M.
that depends on your definition of "the system" and "kill"
finish() destroys an activity
the default behavior of BACK calls finish()
EGHDK
Yeah.
Mark M.
hence, to some extent, "the system" (which is where the BACK press comes from after the user) will "kill" the activity in this case
EGHDK
So the activity is "killed" essentially and it's taken out of the stack.
Mark M.
right
but, in terms of freeing up system RAM, "the system" terminates processes
EGHDK
But can I be in Activity A then go to Activity B and then Activity A will be killed?
Mark M.
not normally
startActivity() does not trigger finish() on the activity calling startActivity()
you can, yourself, call finish() after calling startActivity(), in which case A will be destroyed
EGHDK
So lets say I set a member variable in activity A when I go back to activity A by calling finish on B that variable should still be set?
Mark M.
in simple cases, yes
5:00 PM
EGHDK
So what would a not simple case be?
Mark M.
user is in A
user taps something to go to B
user presses HOME
hours pass
the process is terminated
user returns to the app via the recent-tasks list
this returns the user to B
the user presses BACK
this returns the user to A... but it is a different instance of A than before, because it is a different process than before
EGHDK
Gotcha.
Mark M.
*if* you used onSavedInstanceState() to hold onto this data, then you're fine
if you didn't, you lose it
EGHDK
What if I go to B. Use a ton of ram
then go back to A
Mark M.
your app cannot readily "use a ton of ram"
EGHDK
Where does onSavedInstanceState do though?
Eh. Out of time
Mark M.
and that's covered in the book -- see the chapter on resource sets and configuration changes
EGHDK
Thanks. I'll catch up next time. Because the whole bundle thing in oncreate still confuses me.
Mark M.
because, as you noted, we're out of time
EGHDK
Even from the reading.
bundle thing as in bundle parameter
Mark M.
understood
the next office hours chat is Tuesday at 7:30pm US Eastern Time
EGHDK
Thanks. Good night
Mark M.
have a pleasant day!
EGHDK
has left the room
Mark M.
turned off guest access

Tuesday, August 26

 

Office Hours

People in this transcript

  • EGHDK
  • Gabriele
  • Julius
  • Mark Murphy