Office Hours — Today, January 13

Tuesday, January 11

Jan 13
7:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Suzanne A.
has entered the room
Mark M.
howdy, Suzanne!
Suzanne A.
howdy, Mark!
first, I fixed my db column (and Studio got fixed too)
8:00 PM
Mark M.
cool!
Suzanne A.
so now I have a list pulled from a SimpleCursor adapter, but it's very slooooow
can I subclass SimpleCursorAdapter to recycle views? do you have an example?
Mark M.
slow to load? slow to scroll? something else?
Suzanne A.
slow to scroll, with a big db
Mark M.
SimpleCursorAdapter already does row recycling, AFAIK
what are you displaying in the list?
Suzanne A.
baby names :-) plus a background image
maybe it's the background?
Mark M.
background is per row?
Suzanne A.
I think bg is per list view
Mark M.
you might experiment with removing that, but I doubt it is your problem
so the only thing in the row is a TextView?
Suzanne A.
yes
Mark M.
when you say "a big db", how big?
Suzanne A.
I found this example, but it extends CursorAdapter http://stackoverflow.com/questions/4102219…
db is about 200 rows - maybe not big by your standards
Julius
has entered the room
Mark M.
yeah, that's not big
> 1MB is big
(BTW, howdy, Julius!)
Julius
(hi all)
Suzanne A.
when I scroll, list background goes black and waits ... then redraws bg and shows new rows
Mark M.
well, maybe I was wrong about the background being the problem
David
has entered the room
Suzanne A.
ok. i'm doing lv.setBackgroundResource
Mark M.
Romain Guy has some posts on that, as I recall, either in the Articles area of the Android Developers site, or on his personal blog
you might consider trying Traceview to see what it tells you
(BTW, howdy, David!)
David
Hi Mark,
8:05 PM
Suzanne A.
okay, will do
Mark M.
Julius: do you have a question?
Julius
hi yes:
I have two IntentServices each of which performs writes to my application's database. I get SQLiteExceptions (error code 5: database is locked) if both are running at the same time. Should I bind to the IntentService to find out if an IntentService is active when an application starts?
Mark M.
well, ideally, you synchronize access to the database
Julius
(so as not to start the other process if teh user requests it)
Mark M.
why do you need two IntentServices?
Julius
oh ok... I'm not sure how to go about that
they're both getting data from different places
so one is from online and the other is from a local source MediaStore
Mark M.
I wouldn't consider that a strong design criterion for having more than one IntentService
Julius
so maybe I should combine them into one
?
Mark M.
that would be my gut instinct
Julius
ok great :)
Mark M.
use different action strings, or extras, or something to tell one command from the other
Julius
ok that sounds good
thanks you
Mark M.
David: do you have a question?
David
Yes. What is the best way to transfer data received by Socket to other Activities?
8:10 PM
Mark M.
Let's back up a step. What is opening/using the socket?
David
It is UDP socket.
Mark M.
OK. What is opening/using the socket?
David
Android runs a Server.
Mark M.
OK. What is opening/using the socket? Is it a service?
David
I need to parse UDP packet by server to retrieve some information.
I guess I don't understand your opening/using the socket.
Mark M.
OK.
In Java, you will be creating a Socket or ServerSocket object.
Somewhere, there is a line of code that does this.
That line of code will be in a class.
That class might be a Service, or it might be an Activity, or it might be something else.
David
I got that, and runs okay. Android app is receiving data from other clients which initiates traffic.
I mean UDP server/client is running okay.
Mark M.
OK, but you are not answering my questions, which means I cannot help you.
What sort of class has the code which is opening your Socket or ServerSocket? Is it a Service?
8:15 PM
David
Oh I see. It is Activity. I am consider to use Service.
Mark M.
Yes, your first move should be to have your socket be managed by a Service.
Otherwise, you cannot "transfer data received by Socket to other Activities", since you will be closing that socket when you move to the other activities.
David
But Service is not on all the time, isn't it?
Mark M.
It is far closer to "on all the time" than is an activity
Activities are destroyed frequently.
Users press the BACK button, rotate the screen, etc.
Android kicks activities out of memory if they are not on the screen (e.g., user presses HOME button)
David
That means a packet is arrived, server will run?
Mark M.
There is no "server"
You have a socket
You listen on the socket
This is done by a background thread in a service
when the packet arrives, the service does something, perhaps on another thread if it might take a while
(so as to not interrupt your ability to read packets off the socket)
David
Thank you.
Mark M.
The Services chapter of _The Busy Coder's Guide to Android Development_ outlines a variety of ways your service can send information about this packet to an interested activity.
8:20 PM
Mark M.
I cannot tell you which is best without knowing more about your app, and that is probably beyond the scope of this chat
David
I will closely look at
Mark M.
So, I recommend you review that chapter.
yuku
has entered the room
yuku
umm.. everyone seems idle now.. so, Hi!
can I start a new question
Mark M.
howdy, yuku!
yuku
?
hi again mark!
Mark M.
everyone else has had a turn, so go ahead
yuku
I'm not sure if you always monitor all stackoverflow android question?
Mark M.
no, particularly when I am traveling, like this week
yuku
so, actually I want to re-ask this question http://stackoverflow.com/questions/4583484…
do you have any opinion about how to implement pull-to-refresh in android?
Mark M.
nothing better than the answers you were already given
David
has left the room
Mark M.
what was wrong with the code that johan supplied?
yuku
really? which one from no 1 and 2?
Mark M.
I have no idea
I have not looked at johan's code
He gave you the link
it's the 2-point rated answer
8:25 PM
Mark M.
bear in mind, I have never used a pull-to-refresh app in my life, so I only have a vague notion of what it even means
yuku
I have, but I haven't tried it personally, because it requires animating on the list view using API level 8
hmm, ok, I see, let me see if I can find some info for you
Mark M.
BTW, at this point, I would assume the Twitter app will never be released
Julius
(bugger... :))
yuku
really? what happened to twitter?
Mark M.
they probably took over the app, if I had to guess
Julius
(oh that's Kiwi speak not offensive!)
yuku
Mark M.
:: shrug ::
I haven't the foggiest idea how to do that
heck, just the touch events are pushing the boundaries of my experience
yuku
basically you can pull down the listview and see something on the top of the first item
Mark M.
actually animating based on touch events is well beyond those boundaries
you might look at the implementation of SlidingDrawer and see if you could leverage that as a starting point
yuku
so you think we still need to mess with the touchevent?
hmm
Mark M.
I'm imagining a SlidingDrawer effectively above the ListView
yuku
nice idea
yeah
8:30 PM
Mark M.
as the drawer opens, the ListView resizes smaller
there's a few gaps in the SlidingDrawer implementation compared to what you would need, but it's the closest thing in android.widget I can think of that would be a starting point
yuku
ok, thanks mark!
Mark M.
you could try hunting around to see how the notification drawer works, but I have no idea where that code might live
Suzanne; do you have another question?
Suzanne A.
Yes - you were right - it was the background image. Would using a simple background color affect ListView performance?
Mark M.
that's the article I was thinking of
Suzanne A.
okay, I'll read it - thanks
Mark M.
however, it's not on performance so much as look
ahh
you probably want to set the cache color hint
Suzanne A.
aha .. will try it, thanks
Mark M.
a bit over halfway through the article is the part you need
Suzanne A.
ok
Mark M.
Julius: do you have another question?
Julius
hi yes:
I have a Cursor which I pass into an AsyncTask as a parameter and work through the Cursor. The Cursor is managed using startManagingCursor in an Activity. If I destroy the Activity I get a StaleDataException. Just wondering if you've got any idea why this is occurring or what would be a better thing to do.
Mark M.
I would not pass a managed Cursor into an AsyncTask
8:35 PM
Julius
ah ok
Mark M.
if the activity is destroyed while doInBackground() is rolling, you'll have some sort of problem
Julius
:)
ok
Mark M.
not sure if that's the StaleDataException -- I'd've expected another name
general rule of thumb: don't pass into AsyncTask anything that depends on Activity that you plan to use in doInBackground()
Julius
it tryies to access a cursor that doesn't exist from memory
ok
thanks for that - it sounds sensible.
:)
bfn
Suzanne A.
thanks, mark - bfn
Suzanne A.
has left the room
Mark M.
yuku: do you have another question?
Julius
has left the room
fitz
has entered the room
Mark M.
howdy, fitz!
fitz: do you have a question?
cody
has entered the room
cody
hello.
Mark M.
howdy, cody!
cody: do you have a question?
cody
hi mark! thanks for the great packages and documentation
Mark M.
you're very welcome
8:40 PM
cody
i *did* have questions earlier but i was able to answer them / figure out my issue.
Mark M.
great!
cody
but i will just ask again to see if i was on the right track....
i am using merge adapter and I originally had a regular Activity (NOT ListActivity) and i had a layout with a ListView which I injected with content, and then beneath the listview i had various other views, basically being placeholders for "sorry, no data here" (with visiblity set to gone, which i would switch back to visible when needed). anyways, i was seeing 2 issues
i would populate my merge adapter and its sub-adapters with a bunch of data, and it would render just fine
but on swipe down - the top view in my activity with fundamentally shrink in size, it would go like 1/2 screen width
AND
no click events were happening until after i "primed" the activity by clicking the MENU button. i could click around and they would get queued up but no fire, and then if i clicked the MENU button they would all fire at once.
it was somehow swallowing my events
my solution: switched my Activity to ListActivity and ditched those placeholder layouts
and both problems went away
Mark M.
that's wild
cody
yeah. so my overall question then is
does MergeAdapter require a ListActivity?
i seem to have it working just fine in a reg Activity
but maybe i should switch it too
not seeing those issues on my other activities
but wild indeed
Mark M.
MergeAdapter should not require ListActivity, AFAIK
cody
thats what i thought, especially after looking at the source it seems pretty generic
but good to know
8:45 PM
cody
btw, do you still recommend to inflate views with the 3 param style: inflate(R.layout.foo, parent, true)?
Mark M.
yes
necessary for RelativeLayouts in rows
cody
i saw a stackoverflow thread where you said you might have given us all bad ideas by doing 2 param with null
Mark M.
oh, wait
not, true
inflate(R.layout.foo,parent,false)
cody
i might be able to find it
Mark M.
right
I thought inflate(R.layout.foo, null) was OK a while back
Romain Guy set me straight
cody
yep, thats the thread. he piped up
is that just with RelativeLayout ?
Mark M.
it's the one case I know of
cody
...just an issue with....
makes sense, since a RL will get its layout from its parent, which is the list view. which he addresses in another question of mine
ok, i think it makes sense now
Mark M.
fitz: you haven't had a chance yet -- do you have a question?
cody
hah, sorry for taking over
ok. im good. thanks mark!
8:50 PM
fitz
has left the room
Mark M.
ok, does anyone have a question?
cody
has left the room
9:00 PM
yuku
has left the room
Mark M.
turned off guest access

Tuesday, January 11

 

Office Hours

People in this transcript

  • cody
  • David
  • fitz
  • Julius
  • Mark Murphy
  • Suzanne Alexandra
  • yuku