Office Hours — Today, January 14

Monday, December 21, 2009

Jan 14
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Jan 14
9:00 AM
Mike Q.
has entered the room
Jan 14
9:05 AM
Mike Q.
Hello?
Mark M.
Howdy!
Mark M.
Do you have any Android development questions I can assist with?
Scott Q.
has entered the room
Mark M.
Howdy, Scott!
Scott Q.
Hi Mark
Mike Q.
How are you? I'm am to Android dev and I just signed up to get your books online (and they are great). One thing I'm trying to do and having a problem getting and answer to...
Mike Q.
Trying to use a List and I have an image in the list that I want the user to click on. That image should have a different behavior then if the user clicks on anywhere else in the list but I can't seem to make that happen.
Mark M.
Yeah, I haven't tried having a ListView both use clickable rows and clickable widgets within the rows
Mark M.
I try to stick to one or the other
Jan 14
9:10 AM
Mark M.
I'm not a fan of having too many interaction patterns going on at once -- too confusing for the user
Mike Q.
I see. I noticed they are able to do it in the Gmail app where they have different things in the list that you can click on so i assume it can be done but having a tough time getting any info on it.
Mark M.
I know there's a way to do it, but I don't have the technique at my fingertips.
Mark M.
I'm fairly certain Romain Guy has posted the solution out in [android-developers], though finding anything in there is a bit difficult.
Scott Q.
Mike, I just read a tutorial that was doing that -- I can search for the link and send it to you in a bit
Mike Q.
Ok, well thanks for the time and suggestion. I'll check to see if I can find anything.
Mike Q.
Scott, that would be much appreciated! Thx.
Mark M.
It's one of those things I've been meaning to track down and add to a book, but never quite got around to it...
Scott Q.
I'd need an address to send to though
Mark M.
Ah
Scott Q.
Hi Mark -- I've got a few for ya
Mark M.
Scott: give me one minute to wrap this up
Scott Q.
k, thx
Mike Q.
Please send to mcquaranto@gmail.com
Mark M.
Mike: are you using ImageView or ImageButton?
Mike Q.
ImageView.
Jan 14
9:15 AM
Mark M.
Try switching to ImageButton and call setItemsCanFocus(true) on the ListView
Mark M.
Poking through some back StackOverflow posts, stumbled upon that, and it rang a bell
Mark M.
It may not be the solution, but it's worth investigating
Mike Q.
Ok. The button is not ideal because it puts the image in an actual button so makes sizing of the rows a little more difficult but I will try just to see if that works.
Mark M.
Scott, if you find that tutorial, shoot it to me as well, if you think of it (mmurphy@commonsware.com)
Scott Q.
will do
Mark M.
Scott: your turn for questions!
Scott Q.
I guess I'll start with my listview related question since we're on the topic
Scott Q.
I have a list that has a semi transparent background
Scott Q.
when user scrolls it the transparency goes away
Scott Q.
when user finishes scrolling it stays opaque
Scott Q.
Is there a way to force the transparency back?
Scott Q.
I've tried setting the background explicity but to no avail.
Jan 14
9:20 AM
Mark M.
Are you doing anything with android:cacheColorHint ?
Scott Q.
no
Mark M.
Mark M.
Take a look at that article and see if it gives you any ideas for how to clear up your problem.
Scott Q.
Thanks, I will
Mark M.
Romain Guy = Android UI god
Scott Q.
Ha, I'll remember that. Speaking of hints, I've seen this posted but gone unanswered -- have you noticed
Scott Q.
that when gravity is sent to center_horizontal or center the hints don't show up?
Mark M.
Hints?
Scott Q.
In an EditText object
Mark M.
Oh
Scott Q.
calling SetHint has not effect if you also have gravity set to center
Mark M.
I haven't tried that combination
Jan 14
9:25 AM
Mark M.
If you can create a sample project that demonstrates the problem, and there's no issue for it already on b.android.com, post one there, and shoot me a URL for the issue
Mark M.
Sample projects increase the odds of the issue getting love
Scott Q.
ok, should be simple enough
Scott Q.
can you think of a workaround?
Mark M.
Short of fussing with backgrounds on the EditText, no
Mark M.
A semi-transparent background and a TextView behind the EditText would, in theory give you a similar visual effect
Mark M.
Unfortunately, backgrounds also handle the focus ring and such, so you have a bunch of 9-patch images to modify
Mark M.
Kinda annoying
Mark M.
I'm assuming your gravity is a requirement?
Scott Q.
hmm...ok, sounds like version 1 will have some left justified edittext fields
Scott Q.
just porting an app from another platform and was trying to be consistent wherever I could
Mark M.
Ah.
Scott Q.
Here is one that is hopefully a softball for you...
Jan 14
9:30 AM
Scott Q.
I can't figure out the best way to mirror what I've done in a Windows app -- what is the common practice to launch an activity that should then become the main activity
Mark M.
What do you mean by "main activity"?
Scott Q.
i.e., close the current activity, launch the new one so that when android back button is pressed the first activity does not get activated
Mark M.
Pretty much the way you just described it then.
Mark M.
Let's call them Activity A and Activity B, where A starts B and you want B to be the main activity.
Mark M.
A calls startActivity() and finish()
Mark M.
This will start up B, and A will go bye-bye
Scott Q.
ok, I guess I just assumed that A would remain and I'd have to wait for B to finish before I could call A's finish
Mark M.
startActivity() is extremely asynchronous
Scott Q.
Told you id would be a softball!
Mark M.
so is finish(), for that matter
Mark M.
Almost anything you do in an activity does not take effect immediately
Mark M.
So, let's say you're in an onClick() callback, and you call startActivity() and finish()
Mark M.
Neither startActivity() nor finish() will do anything until after you return from onClick()
Scott Q.
ok, thanks...a point which brings me to my last question...
Scott Q.
I've noticed some of my activities take a long time to render on certain devices making it seem to the user as if their action wasn't recognized
Jan 14
9:35 AM
Scott Q.
How can I provide some kind of visual queue that the activity is starting?
Scott Q.
When I try to effect the UI the changes do not happen before the activity gets rendered
Mark M.
Delay the activity rendering
Mark M.
Scratch that
Mark M.
Is the scenario that the user, say, taps a button or menu item, and the delay is from that point until the next activity (that you're starting with startActivity()) is usable?
Scott Q.
Yes -- user taps the button and the OnClick calls startActivity but nothing happens on the screen for 5 or so seconds which seems like the button press wasn't recognized
Mark M.
Best answer then is to figure out how to accelerate the rendering process, to at least give a partial activity to the user, perhaps with a ProgressDialog
Mark M.
For example, two apps I wrote need to do HTTP I/O to get the data to fill into a list
Jan 14
9:40 AM
Mark M.
I have the activity come up with an empty list, showing something to indicate that we're working on filling in the list (ProgressDialog for one app, RotateAnimation on an ImageView for the other)
Mark M.
I then do the HTTP I/O in an AsyncTask and fill it into the list in onPostExecute()
Mark M.
What is it in your activity that is taking so long?
Scott Q.
Actually let me modify what I said about the flow
Scott Q.
Activity A call Camera Activity B
Scott Q.
after photo is taken buttons appear over the preview
Scott Q.
OnClick from one of these buttons causes some processing on the photo and then calls finish
Scott Q.
onActivityResult from Activity A calls Activity C
Scott Q.
the time between user pressing button on Activity B and then seeing Activity C is a long time
Mark M.
Ah
Scott Q.
but only about 15% of the time is due to the photo processing
Scott Q.
Activity C has a ton of UI in it and I just assumed it was its complexity that was causing the time
Terry S.
has entered the room
Mark M.
If you know that 15% of the time is due to the photo processing, did you measure that the remaining 85% is in the Activity C startup?
Mark M.
Howdy, Terry!
Terry S.
Hi!
Scott Q.
Really all I did was verify that the processing took less than 1 second
Mark M.
OK
Mark M.
What is Activity C doing?
Scott Q.
it has a bunch of options
Scott Q.
several text fileds, toggle buttons, a custom widget with a bunch of 9patch images
Jan 14
9:45 AM
Mark M.
That doesn't sound like the culprit, though
Scott Q.
a lot of stuff in there that is present on the iphone app I am porting
Mark M.
Mark M.
I believe Romain Guy covers method tracing in that Google I/O 2009 presentation
Mark M.
If that isn't it, try this one:
Mark M.
Scott Q.
cool, I will have a watch
Scott Q.
thanks for the tips
Mark M.
I suspect your time is being soaked up elsewhere. I'd try to eliminate the time before I worried about patching over the fact that the time is being taken up.
Mark M.
Anyone else have some quick questions? The time for the office hour is starting to wind down.
Terry S.
One quick one
Terry S.
A composite primary key.
Terry S.
How do you handle with the odd _id thing?
Terry S.
i.e., you cannot have two columns named _id.
Mark M.
Moreover, it has to be a number.
Mark M.
You cannot use composite primary keys and CursorAdapter
Terry S.
OK
Terry S.
So I could build a fake # with two numbers A*100 + B and decode or something.
Mark M.
It's one of the annoying limitations of the CursorAdapter framework
Jan 14
9:50 AM
Terry S.
OK
Mark M.
Presumably
Terry S.
Thanks
Mark M.
I'm used to a composite primary key having some non-numeric component, and those scenarios get decidedly more icky
Terry S.
Another quick one -- limits on total APK size, individual components.
Terry S.
PKs don't have to mean anything, I was just trying to keep the size down.
Mark M.
They need to be small enough that your users will not attempt to tar and feather you
Terry S.
Hmmm, the tar and feather rule.
Mark M.
I am not aware of any limits, though raw resources/assets > 1MB may cause some problems IIRC
Mark M.
Bear in mind that it takes 2x to 4x the space to install an APK
Mark M.
So, if you have a 3MB APK, it will take 6MB to 12MB to install
Mark M.
I think the 4x scenario is if you use the Android Market "copy protection"
Terry S.
OK, if I had a 2 mb file, compressing, decompressing to SDCard and deleting would work?
Mark M.
Deleting what?
Terry S.
The compressed file you wouldn't need anymore.
Mark M.
You cannot modify an APK at runtime
Mark M.
It is signed, sealed, and delivered
Terry S.
Hmmm
Jan 14
9:55 AM
Mike Q.
Can I jump in for one more quick question?
Mark M.
sure
Mike Q.
XML...
Mark M.
(a.k.a., "Attack of the Killer Angle Brackets")
Mike Q.
Have you had any issues parsing XML on the device, especially performance issues if the XML is large?
Mark M.
Sure
Mike Q.
Exactly...
Mark M.
DOM in particular is awful
Mark M.
I don't know what you consider "large", though
Mike Q.
Not sure yet either. But all of the data we're passing to the device is in the form of XML and I could see some of it getting large. Didn't get that far yet but just curious if you've seen performance issues.
Mark M.
Use SAX, or perhaps the XmlPullParser
Mark M.
One performance analysis I saw indicated those two were neck-and-neck in terms of performance, and loads faster than DOM
Mike Q.
Ok, good tip. Thx.
Jan 14
10:00 AM
Mark M.
Another curious possibility is to use android.util.Xml and its newPullParser() method.
Mike Q.
have you used it?
Mark M.
I mentioned once the possibility of using the NDK and SWIG to write a Java API on top of libxml2, to try to boost XML parsing performance.
Mark M.
Ms. Hackborn indicated that "The parsers provided by android.util.Xml are already wrappers around native code, the expat library."
Mark M.
I haven't tried it yet myself to see if getting an XmlPullParser that way is faster than using the XmlPullParser implementation directly.
Mark M.
XmlPullParser is just an interface
Mike Q.
Ah..
Mark M.
It might be that XmlPullParserFactory creates a Java implementation (and, hence, SAX-level performance), while android.util.Xml creates one that uses expat, which might offer better performance.
Mark M.
:: makes note to self to try this sometime ::
Mark M.
Anyway, that's the end of today's office hour.
Terry S.
Thanks so much for all your help!
Mike Q.
Yes, thanks!
Mark M.
I should have one sometime next week, but I don't know quite when yet, so just watch the calendar.
Scott Q.
Thanks Mark!
Mark M.
Also, watch for announcements about new editions of _The Busy Coder's Guide to Android Development_ and _Android Programming Tutorials_ coming out in the next 36 hours or so.
Terry S.
Great!
Mark M.
Have a pleasant day!
Terry S.
You too!
Mike Q.
Same to you.
Mike Q.
has left the room
Terry S.
has left the room
Jan 14
10:05 AM
Scott Q.
has left the room
Mark M.
turned off guest access

Monday, December 21, 2009

 

Office Hours

People in this transcript

  • Mark Murphy
  • Mike Quaranto
  • Scott Q
  • Terry Stough