Office Hours — Today, January 15

Thursday, January 10

Jan 15
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
EGHDK
has entered the room
Mark M.
howdy, EGHDK!
how can I help you today?
Jeff D.
has entered the room
EGHDK
Hey Mark. Couple of questions.
Mark M.
(BTW, hi, Jeff -- be with you shortly!)
EGHDK: give me your first one
Jeff D.
No issues.
EGHDK
Okay, so I'm not sure if you'll be able to answer this question. But, I have a server and I have my mobile application. What is the best way to get them to communicate. I don't feel like I'm doing it the correct way as of right now.
Mark M.
um, could you be a bit more specific? :-)
EGHDK
Yes, sorry, I'm writing up something more specific right now.
7:30 PM
EGHDK
I should get more prepared for these things in the future. lol
Mark M.
Jeff: do you have something quick while EGHDK organizes?
Jeff D.
sure... pg 138...
View paste
setting the Check Box listener.  Why not use the OnClick click even “OnCheckBoxCliced” for us?  Also for the on CheckedChanged…we would have to test for the ID that was given in order to properly set the CheckBox text…we only have one CheckBox, so we are assuming that it’s the only one that can be changed...correct?  
Is oncheckedchanged called by the setoncheckedchangedlistener out of the CheckBox packaged?  Why isn’t the oncheckedchanged part of CheckBox…why does it have to go to a CompundButton for the event?
We only need CompoundButton to handle the OnCheckedChanged, right?  Why is a view being passed?  Why not the button that got the click?
If CheckBox inherits from CompoundButton, why do we need to include the package?
Mark M.
OK
OnClickListener only tells you it was clicked, not the new state
Jeff D.
sorry...had a word document with my questions. Now I know that not all cases are good for setting the 'onclick' in the XML...and im getting to that with fragments
tunneling
has entered the room
Mark M.
if you have more than one CompoundButton for which you are using the same object as the OnCheckedChangeListener, you would need to compare IDs, but we have only one
Jeff D.
so you didn't test for the ID of the object, as you didn't really need to.
Mark M.
CompoundButton is the parent class of CheckBox and handles all two-state widgets, which is why the "checked" stuff is there
Jeff D.
Ahhhh, o.
ok.
Mark M.
CompoundButton, however, is an abstract class, so we have to create things like CheckBox, ToggleButton, Switch
the parameter to onCheckedChange() is the CheckBox (or other CompoundButton) whose state was changed
7:35 PM
Mark M.
and you need CompoundButton.OnCheckedChangeListener because I am not importing that interface directly, and CheckBoxDemo does not inherit from CompoundButton
note that most of this has little to do with Android and everything to do with Java
(BTW, howdy, tunnelling -- be with you shortly)
EGHDK: ready?
:-)
tunneling
Just hanging...
Mark M.
tunneling: OK
EGHDK
View paste
Be prepared for perhaps some weird mumbo jumbo, but I am still consistently confused on how to get data from my database on a server to my Android application.
Right now, I have my site abc.com. I have a page abc.com/menu?today=1_15_2013
From that, it will return the menu for the date given to it. And gives you a quick little html list of the menu.
When I do that in my app, and I get the response, it just doesn't look right. Would it be better to fetch this data from the mysql database directly? So, give my app my database name and database password and have it query for a specific date and return that data?
Mark M.
"Would it be better to fetch this data from the mysql database directly?" -- oh, $DEITY, no
Jeff D.
EGHDK...you are on a totally different level than I am currently. man.
Mark M.
that would imply that your database server was open to the Internet and that your account credentials were baked into your app
neither is a great plan
Peri H.
has entered the room
Mark M.
the typical approach is to create a REST-style Web service, hosted by your Web server, that serves up your data
EGHDK
"EGHDK...you are on a totally different level than I am currently. man." what's that mean? hah.
View paste
"the typical approach is to create a REST-style Web service, hosted by your Web server, that serves up your data"
So I defeinitely do NOT want the credentials baked into my app.
Mark M.
you are welcome to attempt to parse the HTML you get back from the regular Web server, but then if you do a redesign of the site, your app may break
EGHDK
Makes sense.
Jeff D.
EGHDK, I'm still figuring the basics out and you are communicating across sites and using SQL.
Mark M.
the Web service can provide a measure of security that your database won't know how to
and, if the user has an account, you can use things like OAuth to try to use the same authentication logic for both the site and the app
EGHDK
@M
Mark M.
all of that, though, is kinda beyond the scope of the book, and to a large extent, this chat
EGHDK
Gotcha.
7:40 PM
Mark M.
let me take questions from the others, and I'll be back with you shortly
Peri: do you have a question?
Peri H.
Hi Mark.
Yes, I might want to ask about syncadapters.
Mark M.
I haven't used them, so I may not be much help
they're on my list of things to get into in the first half of 2013
Peri H.
I want to address the issue of references from my app to contacts and events.
I have this working quite well righ tnow, using Events._ID and Contacts.LOOKUP_KEY.
However, if the user clears his contacts or events, this breaks. It breaks any time the user deletes something in contacts or events externally, but that isn't too hard to deal with.
The hard part is when they're completely deleted. Then they all get a new set of keys, which may arbitraily match keys in my apps db.
Any suggestions?
Mark M.
"whicih may arbitrarily match keys in my apps db" -- meaning LOOKUP_KEY may have the same value, for different contacts, before and after the bulk deletion?
Peri H.
Less likely for LOOKUP_KEY, but it's pretty easy to make happen with Events.
Mark M.
yeah, ideally, they would have a similar sort of durable identifier for events
EGHDK
Last questions on this app-to-server topic. Since my application doesn't require users to log in or anything. Let's just say I have a daily menu I need to get fetched every day they open the app, I don't need any fancy oAuth stuff right? What would you recommend? As "REST-style web service" doesn't mean much to me. Should I just Google that phrase?
7:45 PM
Peri H.
Event ids start at 1 each time you clear the Events table.
Mark M.
(EGHDK: hang on, I will be with you in a bit)
yeah, I am not seeing anything on CalendarContract.EventsColumns that looks like a durable identifier
Peri H.
So, I think the tactic would be to have my own set of UIDs paired with Events (and Contacts).
It seems that SyncAdapters give you write-access to several columns that could be used for UIDs. Do you know of any other way to do this?
Mark M.
I don't know what the rule is for those SYNC_DATA... columns, but if you can use one for your purposes, yes, having your own UID (or UUID) may work
off the top of my head, no
Peri H.
Any one else know :)
Mark M.
but I have not worked with CalendarContract
that feels like a good StackOverflow question
Peri H.
Ok, off I go...
Thanks.
Mark M.
Jeff: do you have another question?
Jeff D.
195 - Iconic Adapter extends the normal ArrayAdapter…the construct is a different one…valid, but different than normal for the superclass. What does this give us? I can’t find it in the google docs
Peri H.
By the way, if you want to try the app, it's now available at: https://play.google.com/store/apps/details?id=c...
Mark M.
"What does this give us?" -- it gives us a constructor
it isolates some of the details inside the adapter
but you are welcome to do it other ways if you want
and, again, this has little to do with Android and everything to do with Java
Jeff D.
thats kinda what I was guessing, but i wanted to make sure I was interpreting it correctly...i can see why we are doing something a certain way.
Peri H.
has left the room
Jeff D.
when you say that, you mean that a lot of the items are normal ops for Java and not really tied to Android?
7:50 PM
Mark M.
constructors are part of Java
Jeff D.
yes, very true
Mark M.
inheritance and polymorphism are features of Java (from your first question)
they are being *applied* here in Android
Jeff D.
that constructor was different as it took different arguments...was trying to find something in the google docs that could explain the nature of this particular constructor better and why we chose this one.
Mark M.
again, this is Java
Jeff D.
Java is new to me, as I grew up in C/C++.
Mark M.
you can create whatever constructors you want
Jeff D.
yes...
Mark M.
when you create a subclass, you will need to chain to the superclass using one of *its* constructors
but frequently a subclass with have constructors with different parameters than the superclass has
in my case, I elected to move a few things into the adapter and out of the activity
I did not have to do that
that was a personal choice
let me take EGHDK's next question, and I'll be back with you in a bit
(BTW, tunneling, if you come up with a question, let me know)
Jeff D.
you bet...need to chew on that one.
Mark M.
EGHDK: in your case, I am not quite certain what to tell you
either parse the HTML, or create some other output from your server that is more reliable for the app to parse (JSON, XML, etc.)
if all you are doing is consuming the data in the app, the Web site just has to serve something the app can read easily
7:55 PM
Mark M.
OK, if anyone has any questions, chime in
EGHDK
Okay cool, so something like JSON should be pretty easy to do.
Mark M.
simplest way is to just have a separate URL for the JSON stuff
EGHDK
OHH. That makes sense.
Okay, next question. I'm having this issue. http://code.google.com/p/android/issues/detail?...
Or at least, my application is. Someone filed a bug report.
There seems to be a solution, but I'm not sure how to solve it.
Answer?: "regenerate the support-library from the sdk"
Mark M.
yes, you just filed this a minute ago on StackOverflow :-)
EGHDK
Yes!
Mark M.
well, the solution is in the question
EGHDK
I like to take advantage of office hours. I know. hahah
Mark M.
first, make sure you are on the latest Android Support package, in case this was already fixed and they never updated the issue
the source code to the Android Support package is in your SDK
8:00 PM
EGHDK
Okay, so that brings me to another question. Is there a resource to find the newest ASP?
Mark M.
in the same basic spot where you got the JAR from, if you did that manually (vs. via the Add Support Library menu in Eclipse)
it's in your SDK Manager
based on the source code, the latest Android Support package appears to have the fix
EGHDK
Because I get confused with the version numbers.
Mark M.
if the SDK Manager says that you're on the latest, then you're on the latest
however, you have to copy over the JAR to your project
EGHDK
like v11 of Support package and v4 of support package. I get confused.
Is 4 the newest or 11 the newest?
Mark M.
yeah, neither of those are versions of the *package*
they are referring to API levels
hence, neither is the newest, with respect to the Android Support package's own version
EGHDK
Oh. Okay, I should really look into that because it's confused the crap out of me.
Mark M.
in the SDK Manager, in Extras, you will see Android Support Library
if the Status column says "Installed", you have the latest edition
EGHDK
So right now, I should go into eclipse and delete the ASP, and then manually right click my project and re add it?
Mark M.
if the Status column says something like "updates available", then updates are available :-)
in your project, in libs/, you will have android-support-v4.jar (or something like that)
you will need to replace that with the new version of the JAR from the update you get from the SDK Manager
EGHDK
Nope I have Android Support library version 11.
So I'm up to date.
Mark M.
but is that what you're shipping on the Play Store?
IOW, how long has it been since you did a production build and released it on the Play Store?
EGHDK
I released a new version last week.
8:05 PM
EGHDK
But, I don't know if it has the newest .jar
Mark M.
and, comparing your stack traces, the one in your StackOverflow question does not match the issue you linked to here
the issue is complaining about android.app.Notification$Builder.setProgress
your crash is android.support.v4.app.NotificationCompatIceCreamSandwich.add
EGHDK
Bah.
Mark M.
oh, no, wait
never mind
EGHDK
Dangit. Sorry.
Mark M.
hang on
EGHDK
?
Mark M.
your SO question is strange
EGHDK
Hahaha. I just erased it.
Mark M.
oh, wait, now I get it
(that's OK, I still have the browser window open)
add() is where the crash occurred
the error is the one from the issue
EGHDK
Hrm.
Mark M.
however, I suspect that the JAR in your project is older than the rev-11 version from the SDK Manager
again, according to the source code for the Android Support stuff, this bug is fixed
EGHDK
Okay,
Mark M.
you can compare dates/file sizes of the JARs
the one in your project
and the one in your SDK installation
EGHDK
So how do I re-add the new one into my project?
Mark M.
drag it into Eclipse's libs/ directory
it will replace the one you have
extras/android/support/v4/android-support-v4.jar
but check the files first
if the one in your project is much older, then this is likely the reason for the recent crash
and copying over the newer JAR will (hopefully) fix it
Jeff/tunneling: if either of you have a question, chime in
EGHDK
Okay my file in the project is 349,252 bytes, the one in my sdk extras 385,685 bytes.
8:10 PM
EGHDK
So, that seems that it could be the fix... correct?
Mark M.
it's likely
can't guarantee it, but it's likely
tunneling
has left the room
EGHDK
Okay, so in my extras/android/support it has v4 v7 and v13.
Mark M.
go into v4
EGHDK
Those aren't "version numbers"... you said right.
Mark M.
those are API levels
EGHDK
Hmm... so v4 supports down to api lvl 4?
Mark M.
everything in extras/android/support is now rev 11 from the SDK Manager
um, sorta
it's more that if you are developing for older than API Level 11, you want the -v4 JAR
if you happen to be developing for API Level 11+, and just need some compatibility stuff related to ICS/JB, that's what -v11 is for, IIRC
EGHDK
OHH. This makes so much more sense. Thank you so much. The light bulb just turned on. And all the dots connect. hahah. Awesome.
Mark M.
v7 is actually not a JAR, but is a backport of GridLayout as an Android library project
and I really wish they wouldn't have made all that so confusing
EGHDK
I don't have any v11
just v4 v7 and v13.
Mark M.
oh, sorry
EGHDK
Just sayin. lol
Mark M.
replaceAll("11", "13")
EGHDK
Should I?
Mark M.
no, I just was mis-remembering and wasn't looking at my own directory tree
EGHDK
Gotcha. Okay so last thing on this bug report I recieved.
How can I tell what version of android this user had?
8:15 PM
Mark M.
where did you get the stack trace from?
from the Play Store Developer Console?
or by some other means?
Jeff D.
Mark, while he is typing you mind if I jump in?
EGHDK
Play store.
Mark M.
Jeff: please chime in -- I'll try to time-slice between you
Jeff D.
Ok. Ok, I need to go over this a bit more…. You set list adapter via (new IconicAdapter()). This calls the construct…and you are chaining up to the super class (Array Adapter)…. Its taking the DynamicDemo Class, which is being used to do our ListActivitity, …why are you passing the layout.row (XML?), and the id label, in addition to the item array? I know its part of an established constructor, but what are you trying to accomplish? I may need a 'barney style' breakdown to get it through my skull.
Mark M.
EGHDK: I don't have anything currently in the Play Store, but I was under the impression that the Play Store error reports were a bit sparse on information, like the OS version
EGHDK: you might try ACRA: http://acra.ch
"why are you passing the layout.row (XML?), and the id label, in addition to the item array?" -- because ArrayAdapter's constructor needs them
"but what are you trying to accomplish?" -- it helps if our list has data and a format for our rows, otherwise we will not see anything
8:20 PM
Mark M.
you may want to go back to the beginning of the chapter
where all of that is explained
mostly page 172
Jeff D.
ok.
Mark M.
EGHDK: I use ACRA with BugSense as the server component for the APK version of the book, and I get OS version information in my crash reports
8:25 PM
EGHDK
Cool, I'll check that out. In the meantime, I think I'll quickly push an update.
Jeff D.
For the getView(), does Android call that whenever it needs to draw/display a new row?
Mark M.
Jeff: yes
Jeff D.
I'll go over the AdapterViews and Adapters chapter tomorrow...i had some holder questions as well, but I really should just go bac over this.
Mark M.
any last questions?
Jeff D.
Page 252 Options Menus and the Action Bar– does adding a new word to the arrayadapter also add it to the arraylist? Once you setup the arrayadapter to feed off of the arraylist, does it do this automatically?
Mark M.
ArrayAdapter has add(), insert(), and remove() methods that update the backing store (ArrayList) in addition to telling the ListView "yo! our data changed!"
8:30 PM
Jeff D.
Awesome.
No futher here, appreciate the time.
Mark M.
and that's a wrap for today's chat
the transcript will be posted at http://commonsware.com/office-hours/ shortly
the next chat is Thursday at 7:30pm Eastern
have a pleasant day!
Jeff D.
Thanks for your help.
EGHDK
has left the room
Jeff D.
has left the room
Mark M.
turned off guest access

Thursday, January 10

 

Office Hours

People in this transcript

  • EGHDK
  • Jeff DePiazza
  • Mark Murphy
  • Peri Hartman
  • tunneling