Office Hours — Today, October 29

Tuesday, October 27

Mark M.
has entered the room
Mark M.
turned on guest access
Oct 29
7:25 PM
Ken M.
has entered the room
Mark M.
hello, Ken!
how can I help you today?
Ken M.
View paste
Hi Mark! 

There seems to be some disagreement on the best way to associate an app with a file extension, so that extension can be opened by the app from an email attachment, or from something like Dropbox or one of the many file explorers (see http://stackoverflow.com/q/3760276/31629) -- do you have a recommendation for how to best handle this?
Mark M.
well, the best way is to avoid file extensions altogether
as we are moving away from files and more to streams published by ContentProviders
(see Storage Access Framework, runtime permission challenges with external storage, etc.)
and they don't have to have file extension on their Uri values
7:30 PM
EGHDK
has entered the room
Mark M.
now, the question that you linked to has the right idea, relying more on MIME types
this is how the Web works, by and large
(BTW, hello EGHDK -- I will be with you shortly!)
Ken M.
This is for a cross platform app though, that has file extensions on other platforms already -- but maybe there's a way to associate an "extension" or file type use the new way your mentioning? I'll have to look more into the Storage Access Framework.
Mark M.
personally, I avoid file extensions like the plague, but I suspect that yuku's answer on that SO question may be what's needed
Ken M.
Ok, cool, thanks Mark. I have another question but will let EGHDK jump in.
Mark M.
EGHDK: your turn! do you have a question?
EGHDK
Yeah, I guess more of a java question. But I've been stuck for two days on a threading issue ... =(
Or I guess it's threading... its a concurrentmodificationexception
7:35 PM
Mark M.
that will usually come about due to threading issues, where two threads are trying to work with the same collection at the same time
EGHDK
I was wondering if you could take a look at it, to see if theres anything blatantly terrible that I'm doing... http://pastebin.com/0wbWXvjv
Mark M.
some other thread is manipulating the collection returned by getMessages(), while you are iterating over the collection in the code from your pastebin
you have synchronized on this method; are you also using synchronized wherever the other thread is adding/removing from this collection?
EGHDK
Potentially not.
If I synchronize the other method though... that should take care of the issue?
Mark M.
well, it's more that everything that uses the collection needs to be synchronized
that's why I tend to use collections that do the synchronization themselves, out of the java.util.concurrent packag e
er, package
what is the data type of what getMessages() returns?
EGHDK
ArrayList
Mark M.
so, perhaps switch to CopyOnWriteArrayList
7:40 PM
Mark M.
regardless of technique, you need to make sure that while somebody is iterating over the list that nobody else simultaneously adds or removes entries from the list
as that's what triggers a ConcurrentModificationException
let me take another question from Ken, and I'll be back with you in a bit
EGHDK
so lets say only two different methods are using it. having both of them synchronized would work?
Mark M.
Ken: your turn! do you have another question?
Ken M.
I do! What's your advice on whether to store Android Studio's .iml files in source control or not?
Mark M.
I think the consensus is "not"
it gets regenerated from the Gradle build files
Ken M.
Sounds good -- thanks Mark -- these Office Hours are very helpful!
Mark M.
basically, the .iml files (and .idea/ subdirectories) are IDEA files; while IDEA can use other build systems, IDEA still needs its own metadata structures
yeah, I'm consistently surprised that I don't get more people attending them
but, c'est la vie
anyway, back to .iml -- since they get regenerated, they're really output, but can't be stored in build/ due to IDEA limitations (as I understand it)
so, they're just "one of those things" that you have to remember you don't need in version control
EGHDK: back over to you -- do you have another question?
Ken M.
I'm surprised too that they're aren't more people. Seems like people were initially thinking that the iml files SHOULD be checked in but the consensus does seem to have changed.
BTW, the book is great, and like getting the updates all the time. Might be an interesting blog post to talk about the tool chain you use to build the different versions of it.
7:45 PM
Mark M.
the tool chain is MultiMarkdown, PrinceXML, and a bunch of cobbled-together Ruby scripts
EGHDK
so lets say only two different methods are accessing the ArrayList . having both of the methods synchronized would work?
Mark M.
if they are synchronizing on the same object, yes
synchronized as a keyword on the method says "synchronize on the object that this method was called on", IIRC
so, if it's two different methods on the same Java class, synchronized on the methods would allow them to manipulate a common ArrayList (held by the instance of that class) without a ConcurentModificationException
(speaking of Markdown, I *so* wish this chat supported Markdown syntax, particularly when referring to code...)
EGHDK
Mark, but you synchronize methods not objects. How would I then say that this object should be synchronized?
Ken M.
Yes, Markdown would be great here.
Mark M.
OK, let's see how I can explain this in a chat...
the non-method approach to using the synchronized keyword is to have it open up a block, and where you provide the object in parentheses
View paste
so you have: 

synchronized(foo) {
View paste
OK, let's try that again... so you have:

synchronized(foo) {
// something
}
7:50 PM
Mark M.
anything else that is also synchronized on foo will use low-level Java locking stuff to ensure that only one of those synchronized blocks can be executed at a time
and that 2+ threads cannot be in those synchronized blocks
the synchronized keyword on a method is akin to sychronized(this) wrapped around the whole body of the method
so, suppose the class that your pastebin was from is called MessageThingy
cleaner() on MessageThingy has the synchronized keyword
suppose your other method on MessageThingy that works with the ArrayList is call thingamajig()
if you put the synchronized keyword on thingamajig(), then *for the same MessageThingy instance*, two threads cannot be executing thingamajig() and cleaner() at the same time
does that help?
7:55 PM
Mark M.
let me take a question from Ken while you digest all that, and I'll be back with you in a bit
Ken: do you have another question?
Ken M.
Not directly about Android but I'm learning from your sync notes as well. Back to the tool chain, does PrinceXML also produce the epub and mobi formats in addition to the pdf?
Mark M.
no, it just does the PDF
I have a Ruby script that takes the HTML and generates the EPUB, using a Ruby EPUB gem
I have another Ruby script that takes the EPUB and generates the APK
and Amazon's kindlegen tool takes the EPUB and creates the MOBI/KF8
Ken M.
That's cool. I have DocBook source that we use to produce documentation in PDF, Windows and Mac help format, but have never tried build EPUB or MOBI files from it.
Mark M.
I used to use DocBook, for the earlier versions of my book
8:00 PM
Ken M.
Ok, I'm heading out. Thank you very much for all your help, Mark!
Mark M.
EGHDK: do you have another question?
Ken: you are very welcome!
Ken M.
has left the room
8:05 PM
Mark M.
EGHDK: do you have another question?
8:25 PM
Ryan
has entered the room
Mark M.
hello, Ryan!
the chat is almost over -- do you have a quick question?
Ryan
hey!
maybe for next time, just wanted to get a feel for how this worked
Mark M.
OK
basically, you ask questions
I try to give answers
:-)
you can read a few years' worth of chat transcripts at: https://commonsware.com/office-hours/
Ryan
here's a quick question, mipmap folders and drawable folders are basically the same thing, right?
Mark M.
yes, for 99% of use cases
Ryan
alright cool. see ya
Mark M.
in practice, you only use mipmap for launcher icons, at least at the moment
8:30 PM
Ryan
thanks again. see you next time maybe
Mark M.
OK!
the next chat is Saturday at 9am US Eastern
Ryan
has left the room
EGHDK
has left the room
Mark M.
turned off guest access

Tuesday, October 27

 

Office Hours

People in this transcript

  • EGHDK
  • Ken M.
  • Mark Murphy
  • Ryan