Oct 31 | 8:50 AM |
Mark M. | has entered the room |
Oct 31 | 8:55 AM |
Mark M. | turned on guest access |
Oct 31 | 9:10 AM |
Khalil | has entered the room |
Mark M. |
hello, Khalil!
|
Mark M. |
how can I help you today?
|
Khalil |
Hi Mark. Got a question all ready for you. Just let me cut and paste it. One sec
|
Khalil |
View paste
(39 more lines)
|
Mark M. |
sorry, but other than Android proper, I don't use anything from the list of tech that you're trying
|
Oct 31 | 9:15 AM |
Mark M. |
I don't use Google Docs, Google Drive, etc.
|
Mark M. |
let alone use them from an app
|
Mark M. |
so, I have no idea how to really help you
|
Khalil |
Oh ok. Well it was worth a try.
|
Mark M. |
sorry!
|
Khalil |
I guess I am wondering does the app code (for setting the parameters at least) look correct?
|
Mark M. |
I don't know what "correct" would look like, as I have never use those APIs
|
Mark M. |
outside of "...." not being valid Java syntax, I think it'll compile :-)
|
Khalil |
Ok no problem. I will post on SO and see if someone can help me then
|
Mark M. |
but that's about all the further that I can take it
|
Khalil |
It does compile and does call the script but no data passed
|
Khalil |
Alright no issues. I will hit you up for other question when I have them. Thanks anyway!
|
Mark M. |
you are welcome
|
Khalil | has left the room |
Oct 31 | 9:30 AM |
ramsey | has entered the room |
Mark M. |
hello, ramsey!
|
Mark M. |
how can I help you today?
|
Oct 31 | 9:35 AM |
ramsey |
hi mark I hope you're well. I have implemented a sync adapter with a stub contract and stub content provider. When I am syncing the data from the server currently the UI isn't updated because it has a reference to a data structure that has been fetched from the db but it is static. My question is how do I publish progress (eg like in an AsyncTask) from my sync adapter?
|
Mark M. |
while I haven't messed with a SyncAdapter, off the cuff, I would assume publishing an event on an event bus would work
|
ramsey |
I have seen someone suggest sending an intent at the same time you would call publishProgress() but are there any issues with that (eg. memory...? )
|
ramsey |
Ah OK
|
Mark M. |
so, use LocalBroadcastManager, greenrobot's EventBus, etc.
|
ramsey |
I remember reading something about EventBus in your book - that's the best place to go?
|
Mark M. |
in terms of learning about event buses, I like my chapters on the subject :-)
|
Mark M. |
I cover basics in the chapter on threads IIRC
|
Mark M. |
plus there's a dedicated chapter on event bus alternatives in the trails
|
ramsey |
Ha OK I'll work through that then
|
ramsey |
Thanks Mark
|
Mark M. |
happy to be useful!
|
Oct 31 | 9:40 AM |
EGHDK | has entered the room |
Mark M. |
hello, EGHDK!
|
Mark M. |
EGHDK: ramsey has already asked a question, so it's your turn -- do you have a question?
|
EGHDK |
Yeah has to still do with ConccurrentModificationException again. So I went ahead and changed from arrayList to CopyOnWriteArraylist? but I got an error on CopyOnWriteArrayList at runtime.
|
Mark M. |
and the error is... ?
|
EGHDK |
UnsupportedOperationException
|
Mark M. |
can you post the stack trace somewhere?
|
Oct 31 | 9:45 AM |
EGHDK |
So I moved back to ArrayList but I tried to synchronize all my methods again.
|
EGHDK |
These are the only two places where messages member is used. http://pastebin.com/juyz0gka
|
EGHDK | |
EGHDK |
I was wondering if you could see anywhere thats blatantly me modifying concurrently
|
Mark M. |
no, there's more than that
|
Mark M. |
somebody is calling the MsgAdapter constructor, for example
|
Mark M. |
one thread cannot modify that List<Messages> while another thread is using it
|
EGHDK |
But the constructor isn't modifying?
|
Mark M. |
yes, but something else has that List<Messages>
|
Mark M. |
otherwise, nothing could ever create an instance of MsgAdapter
|
Mark M. |
right now, all your synchronized keyword does is ensure that two threads cannot both be running getMessages() at the same time
|
EGHDK |
oh...
|
Mark M. |
and since getMessages() returns the List<Message>, that's *another* place where something has access to the List<Message>
|
Mark M. |
as somebody presumably calls getMessages() at some point
|
Mark M. |
that's why I prefer to use thread-safe collections (e.g., CopyOnWriteArrayList)
|
Mark M. |
you could, instead, create your own MessageList object, and pass that around instead of List<Message>
|
Oct 31 | 9:50 AM |
Mark M. |
have only MessageList work with the List<Message>
|
Mark M. |
and put the synchronization logic in MessageList
|
Mark M. |
I don't know how practical that would be in your situation
|
EGHDK |
So if I didn't want to change data structures... what would be my first move? Look up more places that is touching Messages?
|
Mark M. |
specifically, that List<Message>, yes
|
EGHDK |
Do you think it's the constructor? Theres a sort in there.
|
Mark M. |
that's certainly modifying the list content
|
Mark M. |
yet another possibility is to use Collections.synchronizedList()
|
Mark M. | |
Mark M. |
given a List<Message>, synchronizedList() will return another List<Message>, but one that implements synchronization across all accesses
|
Mark M. |
you'd use this as part of setting up the List<Message>, wherever you are creating it
|
EGHDK |
Hm. That's certainly an option. That's interesting. I wouldn't have to change the structure at all...
|
Mark M. |
this is not as efficient as CopyOnWriteArrayList, but it does implement synchronization at the level of the collection, as opposed to tracking down all the places that are messing with the List<Message>
|
EGHDK |
Gotcha.
|
Mark M. |
I haven't used synchronizedList() in ages, so I don't know if there are any new-ish issues around using it, but, as I said, it's another possibility
|
Oct 31 | 9:55 AM |
EGHDK |
I wonder if I could set a list to like not be modifiable, and then I'll see where it's being modified.
|
EGHDK |
That could make it easier to track down usages I think.
|
Mark M. |
Collections.unmodifiableList() should do that
|
Mark M. | |
EGHDK |
Hmm. You think that's a good debugging option?
|
Mark M. |
don't know -- I have never used it
|
EGHDK |
Okay. Cool. These are all tools in my tool belt now.
|
EGHDK |
Last question.
|
Mark M. |
hold on a sec
|
Mark M. |
ramsey: if you have another question, chime in, as we're running out of chat time!
|
Mark M. |
EGHDK: go ahead
|
EGHDK |
If it is the constructor using Collections.sort() that's causing the issue. Could I create a new Array? right above the sort() call? http://pastebin.com/Ffiukbr0
|
Mark M. |
if you're asking whether MsgAdapter can make its own local copy of the List<Message>, it certainly can
|
Mark M. |
whether or not that's a good thing depends on whether you are expecting changes made elsewhere to affect the MsgAdapter or not
|
Oct 31 | 10:00 AM |
EGHDK |
If I didn't care about that... would I do it like this? ArrayList copiedInvoice = new ArrayList(originalInvoice);
|
Mark M. |
it'd be ArrayList<Message> probably, but otherwise yes
|
Mark M. |
ArrayList has a copy constructor (i.e., a constructor that takes an instance of a similar type and makes a copy)
|
Mark M. |
and that's a wrap for today's chat
|
EGHDK |
gotcha. so it doesn't make a copy with original obj refs? it's original objects
|
Mark M. |
next one is Tuesday, also at 9am US Eastern time
|
Mark M. |
yes, they will be the same Message objects
|
Mark M. |
it will be a different List object
|
Mark M. |
IOW, it does not make a "deep copy"
|
EGHDK |
... Oh. so I don't want that do i?
|
Mark M. |
I have no idea
|
EGHDK |
Okay, thanks. I'll see ya tues
|
Mark M. |
have a pleasant day!
|
ramsey | has left the room |
EGHDK | has left the room |
Mark M. | turned off guest access |