Office Hours — Today, August 7

Yesterday, August 6

Aug 7
10:15 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Chrystian
has entered the room
10:20 AM
Mark M.
hello, Chrystian
my apologies if you were trying to enter the chat earlier
Vinit
has entered the room
Mark M.
my reminder system broke down :-(
hello, Vinit!
Vinit
Hi Mark
No worries!
Mark M.
Vinit: thanks for pointing out my chat room problem!
Chrystian
no problem, I tried 15 minutes ago and just left the window open
Mark M.
Chrystian: you arrived first -- do you have a question?
Vinit
You're very welcome. Glad it wasn't something more.
Chrystian
yes
View paste
I want to use the uses-feature in android to limit my app to only be visible on the play store to devices with a humidity sensor, but I cant find on developer.android.com what the delimited would be for that sensor.
Mark M.
there is nothing for that sensor
most of the sensors cannot be filtered for
Chrystian
that is unfortunate, is there a way to limit my app on the market? besides manually selecting wich device to make the app available for?
Mark M.
not that I can think of
Chrystian
I do not want devices without that sensor to download the app, oh well, I guess I have to make it very clear on the description
Mark M.
the expectation, I suppose, is that few apps *only* work on devices with a humidity sensor
Chrystian
yes
Mark M.
file a feature request on http://b.android.com and pray to the deity of your choice that they add it someday :-)
Chrystian
thank you
Mark M.
ideally, there would be <uses-feature> elements for all of the sensors
Vinit: do you have a question?
Vinit
I came out to check what the chat is about. I do have one, actually. How did you get so involved with StackOverflow as a contributor?
Mark M.
:: shrug ::
StackOverflow hadn't been around all that long, and somewhere along the line I stumbled upon the fact that people were asking questions there
I find SO to be preferable to a Google Group for this sort of support
so I started helping out and publicizing it
Ollie T.
has entered the room
10:25 AM
Vinit
Very cool. Thank you.
Mark M.
plus, for a while, Google was directing people to use it, when they discontinued the old android-beginners group
Ollie T.
Whoo hoo!! :)
Mark M.
hello, Ollie Townsend III!
Chrystian
has left the room
Ollie T.
How are you guys?
Mark M.
sorry about the chat hiccup
turns out that one of my calendar events didn't have a reminder on it...
Ollie T.
Bah, it happens. I just thought it was me since I hadn't been around in a bit
Vinit
I'm enjoying the chat, Ollie. Hope you're well.
Mark M.
Ollie: it's your turn -- do you have a question?
Ollie T.
It's more with the new Android studio
If I recall you are touching on that in the next book update right?
Mark M.
not precisely
Version 5.1 will have a bit of coverage of IntelliJ IDEA
Version 5.3 should have similar coverage of Android Studio
Ollie T.
Ok cool
Mark M.
sometime in 2014, I'll be "mainstreaming" coverage, putting Android Studio on par with Eclipse in the book
(and, oh, what sheer joy all *that* work's gonna be...)
Ollie T.
Ok so basically I should stick to Eclipse for a bit longer lol
Mark M.
well, that depends upon your experience level
I definitely steer newcomers to Android away from Studio while it is in pre-release super-alpha early access preview
(or whatever they're calling it)
Android's tough enough without having to deal with IDE bugs and holes
but, if you have a year or so of Android experience, you'll probably handle those issues better
and if you want to start playing with Studio, that's perfectly reasonable
personally, I'm not planning on touching it until, say, October
Ollie T.
I sort of do want to start playing with it, but I just keep thinking if I get stuck somewhere I wont have you to run to like I normally do lol
10:30 AM
Mark M.
StackOverflow has some people helping on it, and adt-dev is serving well as a Google Group for Studio bugs
(or suspected bugs)
Ollie T.
I am working on a couple new apps and finally decided to start actively using Fragments and am wishing I started that earlier
Mark M.
at least fragments have been around for 2.5 years
and while not everyone has used them, lots have, and they're fairly stable
Ollie T.
I should probably get to my main questions before Vinit yells at me to shut up. :)
Mark M.
actually, let me give Vinit a turn
Vinit
It's cool, Ollie. I'm learning.
Mark M.
Vinit: do you have another question?
Vinit
I do, actually.
Mark M.
go right ahead
Vinit
I know this is covered in the book but I still don't get what the difference between Fragments and Activities are. :-/
Mark M.
activities are your coarse unit of user interface
roughly analogous to a window in a desktop app, or a page in a Web app
Vinit
Roger that
Mark M.
more importantly, like a Web page, they can be internally or externally addressable
if you have an activity with an <intent-filter>, by default other apps, like the home screen, can start up that activity
fragments are chunks of UI
an activity can elect to use fragments as a means of organizing its UI
Vinit
OK. I see.
Mark M.
in particular, fragments are great for UI reuse: master-detail pattern between phones and tablets, multiple pages in a ViewPager, etc.
but fragments themselves cannot exist outside of an activity
and fragments are not individually addressable
10:35 AM
EGHDK
has entered the room
Mark M.
(at least not externally, and not even internally by the same means that we address activities)
Vinit
Cool. Thank you, Mark.
Mark M.
part of the confusion is that fragments did not exist in Android 1.0
any time you bolt something of that magnitude onto an existing architecture, things get weird
hello, EGHDK!
EGHDK
Hello
Mark M.
sorry if you tried entering the chat at 10am and failed -- my chat calendar entry didn't have a reminder attached, and I plum forgot
EGHDK: your turn -- do you have a question?
EGHDK
Just about yesterday with the "encapsulation" thing.
So when I created a method in my activity so my fragment could access it
I had to do getActivity().setAlive(true);
But I had to cast it. Which I don't understand why
Mark M.
if I may ask, what other programming languages do you have experience in? so I can draw an analogy
EGHDK
None really. Some Obj-C but even less than Java
Mark M.
hmmmm... ok
Java is a strongly-typed programming language
by that, we mean that all variables are of some specific type
similarly, all parameters to methods, return values from methods, etc. are of some specific type
EGHDK
I guess I don't get why I had to cast it, because in the fragment I'm doing getActivity() a bunch of times, and Eclipse doesn't complain.
Mark M.
that's because of inheritance
EGHDK
But his one time I'm doing getActivity() it complains
10:40 AM
Mark M.
getActivity() returns a value of type Activity
you can successfully call any methods on that return value that are implemented on Activity
or things that Activity inherits from, like Context
however, the return type is Activity, not EGHDKActivity
and therefore the compiler doesn't think that you can call setAlive(true), because Activity does not have such a method
EGHDK
Oh. So basically all of those things are defined already in a parent somewhere. Gotcha.
Mark M.
however, that's merely an impact of the *return type*, not the underlying object
the object is an EGHDKActivity
casting it allows you to tell the compiler "yo, I gots an EGHDKActivity here, yo"
and so long as you are correct, you will be able to call setAlive(true)
EGHDK
Alright, that makes more sense.
Mark M.
if you are incorrect, and getActivity() is returning something else, you will crash at runtime with a ClassCastException
I realize that diving into Android development is cool and all, but you really should try to carve out some time to go back and learn a bit more about Java itself
EGHDK
Awesome. Alright. Thanks. I'm reading through your blog post about what java fundamentals to know before going into android. Sadly, I don't know most.
Mark M.
you are going to run into brick walls, magic recipes, and the like that's gonna frustrate you
EGHDK
Yeah, I mean I took a class once in high school.
But none of that System.out.println stuff really stuck with me.
And we never did anything that actually really explained cool stuff like inheritance and such
Ollie T.
EGHDK, don't feel bad. I learned most of what I know from here.
EGHDK
Yeah, I wish there was a commonsware Java book. I'd pay good money for that =)
Mark M.
there are tons of Java books
10:45 AM
EGHDK
Exactly!
Don't know which one to pick up!
Mark M.
I learned Java back when dinosaurs roamed the Earth, and so I haven't used anything modern
I know that _Head First Java_ gets rave reviews
EGHDK
Yeah, I heard that too. Might be worth picking up.
Mark M.
anyway...
Ollie: do you have another question?
Ollie T.
Actually I did get that book
Good book.
Intents. (Hopefully that is what I should be looking at using) I want to be able to lets say, receive a message via NFC, QR code, or GCM and have it do something in my app. If the person doesn't have the app I would like them to be directed to the market to download it. Would be an intent or some other type of setup?
Mark M.
well, the GCM option isn't really practical, as you cannot blindly send a message to some device that doesn't have your app on it
NFC on Android supports the Android Application Record (AAR, not to be confused with the AARs associated with the new build system)
you can basically attach a record to the NFC message saying "hey, this message is for this app -- use it, or direct the user to the Play Store for it if it does not exist"
however, it only works with the Play Store (not Amazon AppStore for Android or your own servers)
for QR codes, your best bet is to have one of your activities offer an <intent-filter> that matches an HTTP URL that you control
on devices where your app is not installed, the QR code would lead to your Web site, and you can steer them to download the app
on devices where your app *is* installed, the user will have a choice of running your app or visiting the URL in a browser
Ollie T.
I am looking at doing a sort of scavenger hunt type of thing where a person scans/taps and it registers that they found the spot in the app.
10:50 AM
Mark M.
and you want them to be able to get the app when they encounter the first scavenger hunt item?
Ollie T.
So if a stranger that isn't playing scans/taps I want to offer them the option of downloading. But that part is simple enough. The part I need help with is the "ok you hit this NFC sticker... do this" in the app
Would it be intents or something else?
Mark M.
my understanding is that if you set up the NFC entry on the sticker with an AAR record, it will lead them to the Play Store to install the app
I haven't tried this, as I'm not going to upload some test app to the Play Store for the purposes of experimentation
Vinit: do you have another question?
Ollie T.
That looks exactly like the answer I wanted to hear!
Vinit
Yes, I do. I'm not sure what was meant by internally addressable and externally addressable for the question I'd asked you earlier.
10:55 AM
Mark M.
"addressable" means "we know how to start one"
"internally addressable" means "our own app knows how to start one"
"externally addressable" means "other apps can know how to start one"
Vinit
Ah gotcha. Cool. Thanks.
Mark M.
EGHDK: do you have another question?
EGHDK
Yeah, I have my list. Let me get my next one.
Okay, what does invalidate actually do when called on a view?
Mark M.
at a high level, it tells Android to repaint the pixels for that view and any children (if it is a ViewGroup)
EGHDK
I find it weird that I can do setBackGroundResource(R.drawable.whatever) and then invalidate
Mark M.
you shouldn't need to invalidate()
setBackgroundResource() alone should be sufficient
manual calls to invalidate() are occasionally needed, but not too often
EGHDK
Okay, because there was a SO question, about changing the background, and then he calls invalidate and says that you need it.
Mark M.
try it without it
EGHDK
Okay, well then easy answer I guess. Don't use invalidate unless I need something to be redrawn.
I was really wondering because the navigation drawer tutorial that Google has uses invalidate
Mark M.
I'd phrase it more as "don't use invalidate() unless you try changing something, nothing happens, and adding invalidate() seems to fix the problem"
that's a bit surprising
and I don't see it
11:00 AM
Mark M.
I see invalidateOptionsMenu(), which is something else
EGHDK
Oh. Maybe that's what I saw.
Mark M.
invalidateOptionsMenu() says "please regenerate the action bar contents"
you'll need that particularly if you are looking to add or remove items
EGHDK
Oh. Okay, that makes sense.
SO basically the same thing as invalidate but for the menu items.
Mark M.
in the case of the DrawerLayout sample, the design guidelines say that while the drawer is open, only show action bar items of relevance to the whole activity/app
sorta
Ollie: do you have another question?
Ollie T.
Second question that may not be needed anymore thanks to the NFC bit. Content providers. That is what I was initially looking at to setup this app, and it was way over the top of what I wanted to do I think. I should be able to manage this with just intents right?
Mark M.
using a ContentProvider is orthogonal to your problem
IOW, you may wish to use a ContentProvider as part of your implementation, but it's not really intrinsically tied into the solution
QR codes trigger startActivity() based upon MIME type
NFC tags trigger startActivity() based upon MIME type (and perhaps AAR)
you need to set up <intent-filter> elements on activities to react to those startActivity() requestss
er, requests
and, I'm sorry, but I'm going to need to wrap up the chat, even though we didn't quite get a full hour in due to the late start
Ollie T.
Ok then a content provider would just be more work for no benefit
11:05 AM
Ollie T.
Understood
11:05 AM
Mark M.
the transcript will be posted to http://commonsware.com/office-hours/ shortly
the next chat is tomorrow, 7:30pm Eastern
have a pleasant day!
Ollie T.
you too
Vinit
Cool. Thanks, Mark.
EGHDK
yep
Vinit
has left the room
Ollie T.
has left the room
EGHDK
has left the room
Mark M.
turned off guest access

Yesterday, August 6

 

Office Hours

People in this transcript

  • Chrystian
  • EGHDK
  • Mark Murphy
  • Ollie Townsend III
  • Vinit