Office Hours — Today, November 11

Tuesday, November 9

Nov 11
9:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
10:00 AM
Ales
has entered the room
Ales
Hello
Mark M.
howdy, Ales!
how can I help you today?
Ales
Much better than tuesday :)
Just one quick question. Can I call Toast from a service?
Mark M.
I think so
Dialogs are a problem, but I'm reasonably sure toasts work
I don't do it, personally
10:05 AM
Ales
I read somewhere that it pops up in front of active activity
But not in my case :)
Mark M.
it has to
it's not part of any activity
are you sure the code block where you are show()-ing the Toast is being invoked?
Ales
It should go to queue right
Mark M.
AFAIK, Toasts are not part of the message queue
I think they go straight to the window manager that underlies Android's GUI
Ales
they aren't?
oh didn't know that
btw I really like your books :)
Mark M.
certainly, from a display standpoint, no activity shows the Toast -- that's a window manager thing
thanks!
Ales
With every update everything gets clearer
Explanations I mean...
10:10 AM
Ales
If I have a list of news items with images, is it best to download all images to phone first? Because it seems to be very slow if they are downloading concurrently with news stroy for example.
Mark M.
no, I would download them only when needed
not everybody has an unlimited data plan
and unlimited data plans are not really unlimited
show a placeholder image, then swap in the actual image when it is ready
I have a ThumbnailAdapter and ThumbnailActivity that wrap up the pattern
However, I need to rewrite that someday -- the interface is fine, but the underlying caching logic is messy
Ales
Is a game hard to programm (create) for beginners?
10:15 AM
Mark M.
Beats me
I haven't written a game in two decades
Not my cup o' tea, as it were
Ales
I looked on market and games always have a lot of downloads, much more then apps
Mark M.
That's very possible
Ales
Still trying to solve than ANR, it's making me crazy :)
Mark M.
did you post an issue to StackOverflow?
10:20 AM
Ales
Well, not yet. It's hard to explain
Mark M.
ok
Ales
My app currently looks like this http://tehnik.mobitel.si/wp-content/upload…
It's my first project :)
Mark M.
nice!
though the green-and-orange theme is not quite my style :-)
did you do the icons and backgrounds yourself, or do you have somebody else who does your graphic work for you?
Ales
Not my fault :) Designer did GUI
Mark M.
ah, OK
Ales
It's kind of RSS app
So I have like news, weather, traffic on top
Mark M.
for Slovenia, presumably
Ales
Those are my main activities.
How do you know
10:25 AM
Ales
Oh
From image :)
Mark M.
yeah, I can't read much on there, but I figured that Slovenia was a good guess
Ales
nicely done
Those are sections like World, Sport, Politics, Tech,...
Below is a RSS icon
There is my problem with ANR. If I start my application and access it with long click it works fine.
Mark M.
"access it with long click" -- what is "it"?
Ales
But if I switch between those icons on top and then go to RSS source selections ANR show up
onlong...
Mark M.
"it" is the RSS button?
Ales
Yes
I mean activity starts
Mark M.
what happens when you long click on it (and it works -- not the ANR case)?
Ales
A list of sources displays
Mark M.
where are those sources coming from: a local database, an HTTP request, or something else?
Ales
You don't have emulator handy right?
Mark M.
sure
Ales
Database, but there only are like 6 or so
10:30 AM
Mark M.
OK, so that shouldn't be the problem
Ales
Would you mind trying apk?
Mark M.
often times, with apps like this, you accidentally do an HTTP request on the main application thread, and that can cause problems
trying the APK probably will not help
since I don't have the source
probably the ANR is coming when the sources activity is starting up
the most likely culprits, then, are whatever work you are doing in onCreate(), onStart(), or onResume()
Ales
Hmm, maybe image downloading... But as I mention list does show up very fast. I just can't check any of my checkboxes
Mark M.
oh, right
forgot about that
OK, so you long-press the RSS feed button, the sources list is displayed, and then you get ANRs when you try interacting with the list -- right?
10:35 AM
Ales
correct
Mark M.
then something else is stealing the main application thread after onResume()
otherwise, you wouldn't see the list
Ales
And it always works fine if I go to sources list immediately after I start my app.
Mark M.
the ANR dialog will tend to appear when you try tapping on an activity and your touch events are just getting queued up
that may mean that the sources activity is not the problem, but something else (e.g., those images) is
double-check to make sure all of your HTTP operations are done in AsyncTasks or otherwise on a background thread
also, the images that you are downloading -- are they really the right size, or are you downloading full-size images and then having to scale them to be thumbnails?
Ales
No scaling in app
Mark M.
OK, then that's not it
Ales
Oh one more question
Mark M.
HTTP operations, Thread.sleep(), infinite loops -- those are the typical ANR sources I've encountered
Ales
When I say ImageView with android:width="100dp". What happens with image if it's bigger?
Mark M.
it gets scaled
or cropped
see android:scaleType for the options
10:40 AM
Ales
So there is some scaling i guess
Mark M.
are you downloading really big images that are being scaled? or is it that you are downloading thumbnails but not quite the right size?
Ales
No no i do thumnails on web server
But since devices have different resolution
Mark M.
ah, I see
Ales
Android probably scales a bit
Mark M.
you have two choices
1. what you're presently doing
2. have different thumbnails on your server, and download the right set
in that case, you wouldn't use 100dp, but rely on the image itself to have the right size (e.g., android:layout_width="wrap_content")
and you'd have different directories or filenames or URL parameters or something to get the right thumbnail for this density
advantages: crisper images, less on-device CPU usage
disadvantages: more server code and complexity
Ales
I should do that yes.. still a lot of devices to cover :)
I must learn proper DPI conversion though
10:45 AM
Ales
Any Gingerbread news yet :)
Mark M.
latest rumors say it'll ship today
hasn't shipped yet, though
10:50 AM
Ales
Wow only me today :) Was packed two days ago
Mark M.
yeah, these chats are feast or famine
usually they are fairly quiet
the 4pm Eastern time is a new one, and so maybe there is pent-up West Coast demand or somethign
er, something
Ales
It's 16:51 here :)
Slovenia
But you are just starting your day
Mark M.
yes, I am surprised you were on Tuesday's chat, as that is rather late in your time zone
Ales
It wasn't to bad. It was like 16 right?
So it was about 22 here
Mark M.
right
Ales
Those 20:00 are a killer :)
Mark M.
well, yeah
that's why I rotate between times as best I can
to try to give everybody a shot at a reasonable hour
Ales
Well Mark, thank you very much for your time.
Mark M.
sure! happy to help!
Ales
Keep regular book updates and we'll be more than happy
10:55 AM
Mark M.
I do my best
Ales
Thanks again, bye
11:00 AM
Ales
has left the room
Mark M.
turned off guest access

Tuesday, November 9

 

Office Hours

People in this transcript

  • Ales
  • Mark Murphy