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!
|
Mark M. |
how can I help you today?
|
Ken M. |
View paste
|
Mark M. |
well, the best way is to avoid file extensions altogether
|
Mark M. |
as we are moving away from files and more to streams published by ContentProviders
|
Mark M. |
(see Storage Access Framework, runtime permission challenges with external storage, etc.)
|
Mark M. |
and they don't have to have file extension on their Uri values
|
Oct 29 | 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
|
Mark M. |
this is how the Web works, by and large
|
Mark M. |
(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 ... =(
|
EGHDK |
Or I guess it's threading... its a concurrentmodificationexception
|
Oct 29 | 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
|
Mark M. |
you have synchronized on this method; are you also using synchronized wherever the other thread is adding/removing from this collection?
|
EGHDK |
Potentially not.
|
EGHDK |
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
|
Mark M. |
that's why I tend to use collections that do the synchronization themselves, out of the java.util.concurrent packag e
|
Mark M. |
er, package
|
Mark M. |
what is the data type of what getMessages() returns?
|
EGHDK |
ArrayList
|
Mark M. |
so, perhaps switch to CopyOnWriteArrayList
|
Oct 29 | 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
|
Mark M. |
as that's what triggers a ConcurrentModificationException
|
Mark M. |
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"
|
Mark M. |
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
|
Mark M. |
yeah, I'm consistently surprised that I don't get more people attending them
|
Mark M. |
but, c'est la vie
|
Mark M. |
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)
|
Mark M. |
so, they're just "one of those things" that you have to remember you don't need in version control
|
Mark M. |
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.
|
Ken M. |
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.
|
Oct 29 | 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
|
Mark M. |
synchronized as a keyword on the method says "synchronize on the object that this method was called on", IIRC
|
Mark M. |
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
|
Mark M. |
(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...
|
Mark M. |
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
|
Mark M. | |
Mark M. | |
Oct 29 | 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
|
Mark M. |
and that 2+ threads cannot be in those synchronized blocks
|
Mark M. |
the synchronized keyword on a method is akin to sychronized(this) wrapped around the whole body of the method
|
Mark M. |
so, suppose the class that your pastebin was from is called MessageThingy
|
Mark M. |
cleaner() on MessageThingy has the synchronized keyword
|
Mark M. |
suppose your other method on MessageThingy that works with the ArrayList is call thingamajig()
|
Mark M. |
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
|
Mark M. |
does that help?
|
Oct 29 | 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
|
Mark M. |
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
|
Mark M. |
I have a Ruby script that takes the HTML and generates the EPUB, using a Ruby EPUB gem
|
Mark M. |
I have another Ruby script that takes the EPUB and generates the APK
|
Mark M. |
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
|
Oct 29 | 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?
|
Mark M. |
Ken: you are very welcome!
|
Ken M. | has left the room |
Oct 29 | 8:05 PM |
Mark M. |
EGHDK: do you have another question?
|
Oct 29 | 8:25 PM |
Ryan | has entered the room |
Mark M. |
hello, Ryan!
|
Mark M. |
the chat is almost over -- do you have a quick question?
|
Ryan |
hey!
|
Ryan |
maybe for next time, just wanted to get a feel for how this worked
|
Mark M. |
OK
|
Mark M. |
basically, you ask questions
|
Mark M. |
I try to give answers
|
Mark M. |
:-)
|
Mark M. |
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
|
Oct 29 | 8:30 PM |
Ryan |
thanks again. see you next time maybe
|
Mark M. |
OK!
|
Mark M. |
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 |