Office Hours — Today, October 31

Thursday, October 29

Oct 31
8:50 AM
Mark M.
has entered the room
8:55 AM
Mark M.
turned on guest access
9:10 AM
Khalil
has entered the room
Mark M.
hello, Khalil!
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
View paste (39 more lines)
Hi, 
I will try and keep it as brief as I can. I am currently attempting to send data from my Android app to a Google Sheet created on Drive using background syncing (Sync Service) 
I have based the script call off of the "QuickStart" here: https://developers.google.com/apps-script/guides/rest/quickstart/android (which I tried and worked fine).

However now in my app I need to actually send it some data (parameters)

I looked at the JavaDocs for the ExecutionRequest function and saw there is the ability to setParameters. So I created a JSON string using Gson from a class and added that to the parameters. I have logged the string before sending and it looks correct. However when I try access the property in the Sheet it tells me it is undefined


SENT JSON =>  "studentFolderID":"xxxxxx"}


Here is my simplfied JAVA code that sends the data

	private List<String> sendDataToGAS()
...
Mark M.
sorry, but other than Android proper, I don't use anything from the list of tech that you're trying
9:15 AM
Mark M.
I don't use Google Docs, Google Drive, etc.
let alone use them from an app
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
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
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
9:30 AM
ramsey
has entered the room
Mark M.
hello, ramsey!
how can I help you today?
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...? )
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 :-)
I cover basics in the chapter on threads IIRC
plus there's a dedicated chapter on event bus alternatives in the trails
ramsey
Ha OK I'll work through that then
Thanks Mark
Mark M.
happy to be useful!
9:40 AM
EGHDK
has entered the room
Mark M.
hello, EGHDK!
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?
9:45 AM
EGHDK
So I moved back to ArrayList but I tried to synchronize all my methods again.
These are the only two places where messages member is used. http://pastebin.com/juyz0gka
I was wondering if you could see anywhere thats blatantly me modifying concurrently
Mark M.
no, there's more than that
somebody is calling the MsgAdapter constructor, for example
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>
otherwise, nothing could ever create an instance of MsgAdapter
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>
as somebody presumably calls getMessages() at some point
that's why I prefer to use thread-safe collections (e.g., CopyOnWriteArrayList)
you could, instead, create your own MessageList object, and pass that around instead of List<Message>
9:50 AM
Mark M.
have only MessageList work with the List<Message>
and put the synchronization logic in MessageList
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
yet another possibility is to use Collections.synchronizedList()
given a List<Message>, synchronizedList() will return another List<Message>, but one that implements synchronization across all accesses
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
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.
That could make it easier to track down usages I think.
Mark M.
Collections.unmodifiableList() should do that
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.
Last question.
Mark M.
hold on a sec
ramsey: if you have another question, chime in, as we're running out of chat time!
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
whether or not that's a good thing depends on whether you are expecting changes made elsewhere to affect the MsgAdapter or not
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
ArrayList has a copy constructor (i.e., a constructor that takes an instance of a similar type and makes a copy)
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
yes, they will be the same Message objects
it will be a different List object
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

Thursday, October 29

 

Office Hours

People in this transcript

  • EGHDK
  • Khalil
  • Mark Murphy
  • ramsey