Office Hours — Today, April 12

Tuesday, April 10

Mark M.
has entered the room
Mark M.
turned on guest access
Daniel B.
has entered the room
Mark M.
howdy, Daniel!
how can I help you today?
Daniel B.
Hi :)
is it possible to have a Loader that is dependant on another loader having finished it's load?
Mark M.
in theory, if you do not init the second loader until the first one is done, that should work
I have not tried that, though
Apr 12
10:00 AM
Daniel B.
ok, because I have one loader which is grabbing data to populate a spinner, but need another loader which is getting the id (from another table - like a foreign key) and then goes to the right position in the spinner, but what i find is that the spinner isn't loaded yet, so when its comparing it just sticks on first entry
10:00 AM
Ben K.
has entered the room
Ben K.
Hello
Mark M.
howdy, Ben!
Daniel: that sounds like you need to wait to update the Spinner until both loaders are done
oh, no, wait
never mind
wasn't thinking straight
again, if you wait to init the 2nd loader until the 1st is done, in theory that should work fine
Daniel B.
so you think init the 2nd loader onLoadfinished of the first loader?
Mark M.
it's certainly worth a try
Daniel B.
I'll give it a try :) thanks!
Mark M.
Ben: do you have a question?
Ben K.
Yes I have a handler that is being used with a background thread. It works well when the activity it is a field in has focus. However, when I leave the activity and navigate back in, it does not work.
It still gets updates but notifyDataSetChanged doesn't work
Mark M.
please define "it does not work"
Ben K.
I have an adapter I'm updating from within the handler
Mark M.
what do you mean by "leave the activity and navigate back in"?
Ben K.
The activity loses focus to another activity, then regains focus
Mark M.
if the Handler is still processing messages, then your problem would not appear to be with the Handler, but perhaps with the Adapter
10:05 AM
Mark M.
are you sure this is the same Adapter as before? (i.e., you did not create a new one)
Ben K.
Actually that might be the problem, I do create a new Adapter in onCreate
Mark M.
if your Handler still has a reference to the old Adapter, that would explain matters
Ben K.
I see. How can I maintain a reference to the old adapter
Mark M.
by holding onto it
(e.g., the Handler holds the Adapter in its own data member, which is not being updated)
Ben K.
Well another thing is that in onCreate I create a new handler, so that might be a problem. However, the handler still gets updates.
Mark M.
Daniel: do you have another question?
Daniel B.
Yea
How do I populate the checkbox (selected, not selected) in a ListView
10:10 AM
Mark M.
Daniel: setItemChecked()
Ben: onCreate() actually shouldn't be called in this case
Daniel B.
I can set its label from the to parameter in the adapter, but not its checked
Mark M.
your old activity should just have been paused and stopped, and then started and resumed, when it returned to the foreground
Ben K.
I see
Mark M.
Daniel: call setItemChecked() on the ListView
Ben K.
Should I use onRestoreInstanceState to hold onto the Adapter?
Mark M.
Ben: you can't, nor should you need to -- your activity did not go anywhere
let's call this activity A
A starts Activity B
at that time, A is paused and stopped
if the user presses BACK on B to return to A, A is started and resumed
it is still the same instance of A, so you should have your same Handler, Adapter, etc. -- onCreate() should not be called
Ben K.
Ok
10:15 AM
Mark M.
if the Handler is still talking to the same Adapter, and the Adapter is still in your AdapterView, then notifyDataSetChanged() should still work
if notifyDataSetChanged() is not working, then something in this chain is broken
and I have no way to tell you what, specifically
Ben K.
Ok I'll take a look
Thanks!
Mark M.
if anyone has another question, chime in
Ben K.
That's all I have, thank you.
Ben K.
has left the room
Daniel B.
Don't think this is a very good question but, If I set on a TextView, maxLength is there a way to ellipsize when it gets to that length? Right now just cuts it off
Mark M.
use android:ellipsize
Daniel B.
yep, I have been, but its not technically reached the end of the ListView so it does not ellipsize
10:20 AM
Mark M.
oh
10:20 AM
Mark M.
that's disappointing
you'd have to manage that yourself then, detecting the length of the string and introducing an ellipsis as needed
Daniel B.
Ah ok, as I thought. Thought i'd ask incase I missed something obvious
10:25 AM
Daniel B.
Thanks for your help
Daniel B.
has left the room
10:50 AM
Al K.
has entered the room
Mark M.
howdy, Al!
how can I help you today?
Al K.
I have some questions about PendingIntent.
Mark M.
OK, go ahead
10:55 AM
Al K.
I was sending a broadcast and including a PendingIntent for the purpose of getting a callback. Also I included some specific data as an extra in the pendingIntent expecting to receive this data in the callback.
This process gets repeated with a different set of call-specific data as an extra.
Mark M.
ah
let me guess: you keep getting the original extras, right?
Al K.
The first call and response worked OK. the 2nd call gets the extras from the first call. So yes what you said.
Mark M.
you need to include a flag when you create your PendingIntent, such as FLAG_UPDATE_CURRENT
PendingIntents are cached
if you try to create a PendingIntent for the same Intent (ignoring extras), you get the cached PendingIntent back
and that cached PendingIntent has the original Intent inside of it
FLAG_UPDATE_CURRENT replaces the Intent with your new one
or, FLAG_ONE_SHOT stops the caching (if I understand correctly -- I haven't used this one personally)
these flags are documented on PendingIntent and would be included in your call to getBroadcast(), getService(), or getActivity() where you are requesting a PendingIntent from the OS
11:00 AM
Al K.
Yes, it looks like FLAG_ONE_SHOT may be what I want.
Mark M.
OK, that's a wrap for today's chat
Al K.
Or I have a work-around by passing additional extras with the original broadcast, and expecting them to be explicitly returned when the pendingIntent is used.
OK, thanks.
Mark M.
that could work too, though I think you are better served with one of the FLAG_ values
next chat is Tuesday at 4pm Eastern
have a pleasant day!
Al K.
has left the room
Mark M.
turned off guest access

Tuesday, April 10

 

Office Hours

People in this transcript

  • Al Kepner
  • Ben Krack
  • Daniel Bell
  • Mark Murphy