Office Hours — Today, December 2

Yesterday, December 1

Dec 2
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
Johnny
has entered the room
Mark M.
hello, Johnny!
how can I help you today?
Johnny
Hi Mark
I'm currently building a new app and it requires dealing with prices. I've looked at SO and you mentioned that storing prices as an int value seems to be the best so, $5.30 as 530 etc. Is this still true?
Mark M.
compared to using something like float, yes
Johnny
I've used BigDecimal before but I think this seems cleaner
9:05 AM
Mark M.
BigDecimal is great for Zuckerberg-sized prices :-)
for more... conventional monetary amounts, you will probably find int to be faster
Johnny
Haha thanks, gottcha
Mark M.
they key is to set the units to be something that cannot be subdivided
so, for example, in the US, *usually* things are priced to the cent ($5.30)
gallons of gas, however, tend to get priced to the tenth of a cent
if your currency is Bitcoin, things get priced to a very small decimal fraction of a Bitcoin
so, you choose the "atomic" unit for the currency, and skip trying to do anything sub-atomic
Johnny
Interesting. Though since this is a budget app, I think it should be ok to leave it in cents. And I understand other currencies have different decimal precisions
Yep cool
Mark M.
yeah, your case is probably one of the simpler ones
9:10 AM
Johnny
In the same app I'm dealing with time. Would you say a pure Unix timestamp is best? Instead of Joda Time etc.
Mark M.
in terms of what you persist, a Unix millliseconds-since-the-epoch value is reasonable
in terms of what you use in Java to represent that, that's up to you
I haven't used Joda Time personally
and I seem to recall that Jake Wharton released a slimmer date/time library for Android relatively recently
Johnny
Ah right, will check that out. Thanks
9:15 AM
Mark M.
if you have any additional questions, go right ahead -- it is a quiet chat room today
9:20 AM
Johnny
View paste
Also just wondering, in the fragment's life cycle, what should really go in onCreateView() and onViewCreated(). I've actually always done a lot of the view binding (findViewById / butterknife) and adapter setup inside onCreateView(), but now I'm questioning if those shouldn't be in onViewCreated() instead and just have the view inflation done in onCreateView(). The doc doesn't really help and Google's sample code as well as other books have all those things done in onCreateView().

Though, this resource kind of does say to use onViewCreated() https://github.com/codepath/android_guides/wiki/Creating-and-Using-Fragments#fragment-lifecycle
Mark M.
personally, I override one or the other, not both, for a given fragment, usually
if I am inheriting onCreateView() (e.g., ListFragment), I override onViewCreated()
if I am implementing onCreateView(), I just do all the work in there
now, if I were writing a library, where I was expecting others to extend *my* fragments, I would want to think through what the best solution would be
and that might vary by circumstance
Johnny
Ah right. Guess it really doesn't matter that much. Though oncreateview() shouldn't return the inflated view as fast as possible right? Might be a misconception I have
Mark M.
I doubt that it makes a significant difference
it's not going to show up until both methods have been invoked anyway
unless the implementation is a lot screwier than I think it is
9:25 AM
Johnny
haha yeah. I'm just guessing the internal workings of it at the moment. Thanks though
If you don't mind, I got another question
Mark M.
go right ahead
9:30 AM
Johnny
View paste
This is just design choice, but would you have a toolbar be associated with a Fragment or Activity?
Well, my situation is I have a detail activity, and it holds a single fragment. Now I'm using the Toolbar, coordinatorLayout to create the parallax effect. If I make the activity have the toolbar then I need the Fragment to pass information back up (breaking encapsulation) and can't really be reused, e.g. in tablet master-detail view
Mark M.
well, I haven't messed with CoordinatorLayout and the like
and I have not really pondered what that sort of parallax behavior would be like on a tablet
from what you describe, it sounds like the Toolbar should be owned by the fragment
at least until you come up with some compelling scenario that forces your hand in another direction
Johnny
Ah ok. I've currently got it as part of the Fragment and it works, but haven't tried for tablet and not needed at the moment
9:35 AM
Johnny
How would you handle threading in a Service? Firing off an IntentService, using Executor or RxJava even?
Mark M.
I have not used RxJava
of the first two options, it depends on the threading model I need
IntentService is great, but there's only the one thread
if I need parallel work, I'd create my own Executor-based Service
one of these days, I'll have the itch to scratch and will create the MultiIntentService or ThreadPoolIntentService or something
9:40 AM
Johnny
Interesting. Sounds pretty neat. Thanks
That's all the questions I got. Thanks so much Mark
Mark M.
you are very welcome
Johnny
Enjoy the rest of your day :)
Mark M.
you too!
10:00 AM
Johnny
has left the room
Mark M.
turned off guest access

Yesterday, December 1

 

Office Hours

People in this transcript

  • Johnny
  • Mark Murphy