Office Hours — Today, September 9

Thursday, September 5

Sep 9
3:50 PM
Mark M.
has entered the room
Mark M.
turned on guest access
3:55 PM
Jeff
has entered the room
Mark M.
hello, Jeff!
how can I help you today?
Aditya
has entered the room
Mark M.
hello, Aditya!
Aditya
Hi everyone!
Mark M.
how can I help you today?
Luca
has entered the room
Aditya
So I need help, I have to create a service which can download multiple files and show the progress of the download as a notification
the sameway the download manager does
Mark M.
(BTW, hello, Luca -- I will be with you shortly!)
Luca
hi all, ok
4:00 PM
Aditya
I dont need source code I just need to be pointed to the resources so I can make it myselk
but if a solution already exists I wont say no
Mark M.
what specific parts of this are you seeking resources for?
Aditya
making the service talk to the notification and update the notification as files get downloaded
Mark M.
that's covered in the book
see the Advanced Notifications chapter
Aditya
thanks!
Mark M.
page 1169 in the Version 5.1 PDF
Luca: do you have a question?
Luca
yep
activity leak
View paste
a little preface: If i create a simple activity, with strict mode enabled, and i keep changing orientation i notice some warning like "InstanceCountViolation;instances=2;limit=1"
If i understand correctly this is perfectly normal because the old activity isn't GCed instantly, for example if i add an explicit GC on each orientation change the warning disappear
Is that correct?
Mark M.
I have seen that too
so far, I have been interpreting it as StrictMode being a bit aggressive about when it reports a problem
Luca
ok now the real question:
View paste
I have noticed that the main activity of my application is showing the same warning but with "instances=3", in this case if i add an explicit GC on each orientation change the warning will still show up but with "instances=2"
This means that there is some leak that i have to avoid? Or even in this case can be normal and is caused by something like loaders and other things?
Mark M.
it may or may not be a leak
use MAT to determine for certain
4:05 PM
Luca
ok thank you i have two other question
Mark M.
let me take questions from the others, and I will be back for your next one shortly
Jeff: do you have a question?
Luca
ok
Mark M.
hmmmm
Aditya: do you have a question?
OK, Luca, back to you: what is your next question?
Luca
Can i use "new Thread(code).start()" directly for short tasks where i don't need ui callbacks or there are some drawbacks?
Mark M.
if you plan on doing a lot of them, I'd consider some sort of thread pool
otherwise, a plain thread is perfectly fine
Luca
ok, can i go with the next?
Mark M.
sure
Luca
View paste
I want to encrypt some files with AES, i have first tried CipherInputStream/CipherOutputStream but they are slow and cause a lot of GC. 
Now i'm using a JNI wrapper that uses openssl to encrypt and decrypt with some java callback for progress (one per percentage point).
Do you have some suggestions to further improve this or any better alternatives?
Mark M.
JNI with OpenSSL is a reasonable approach
SQLCipher for Android uses it, for example
4:10 PM
Mark M.
in fact, if you're not already doing so, I'd recommend bundling in your own copy of OpenSSL
the SQLCipher team just moved to that model
Jeff/Aditya: do you have any questions?
Luca
i have compiled my own version of openssl because i had read to not trust much libraries that come with android
Mark M.
if anyone has any questions, feel free to chime in
4:15 PM
Luca
In the future i will also need to use sqlcipher i wonder if in some way i can use the same bundled version of openssl both for sqlcipher and my jni
Mark M.
AFAIK that should be possible, but I'm far from an NDK expert
Alex
has entered the room
Luca
ok thank you
Alex
Hello
Mark M.
hello, Alex!
Alex: do you have a question?
Alex
Yeah. About BroadcastReceivers
Mark M.
Alex: go ahead
Alex
If a BroadcastReceiver is registered via manifest, at what point will it stop receiving broadcasts or does it not? In other words, if the process that's tied with an app dies, does the broadcast receiver sort of die with it?
Mark M.
no, the process being terminated (for "natural causes") will not stop you from receiving broadcasts
"Force Stop" from Settings will, however, block your receipt of future broadcasts, until the user runs one of your activities
4:20 PM
Mark M.
and my understanding is that a few devices from boneheaded manufacturers do the "Force Stop" behavior from their own replacement task managers, which sucks
fortunately, that does not seem to be widespread
Aditya
has left the room
Mark M.
if anyone has any questions, chime in
Alex
oh ok. thanks.
so, i would assume that if the OS decided to stop my applications' process and it can still receive broadcasts, does that mean it's not really stopped? sort of running, but not really running?
Mark M.
no
4:25 PM
Mark M.
a system-level process maintains the roster of <intent-filter>s
when a broadcast is sent, it looks up matches in the roster
Alex
gotcha
Mark M.
if needed, it starts a process to deliver the broadcast to a specific receiver
Alex
makes sense
Mark M.
Alex: if you have another question, go ahead
Alex
I'm good for now. thanks though.
Thanks again. been helpful.
Alex
has left the room
Luca
i have another question, tell me when i can ask
Mark M.
go right ahead!
Luca
View paste
I have a singleton class that has the purpose to be the "datamanager", internally it instantiate a global SQLiteOpenHelper 
On every method where i need to interact with the database i'm calling something like "helper.getWritableDatabase().query". 
Do i need to ensure that the SQLiteDatabase is closed with a try/finally in every method?
In alternative can i use directly a global SQLiteDatabase initialized with "helper.getWritableDatabase" when the "datamanager" singleton is created or is a bad approach?
Mark M.
"Do i need to ensure that the SQLiteDatabase is closed with a try/finally in every method?" -- no
4:30 PM
Mark M.
in fact, you don't want to close the database until you are *completely done with it*, from all threads
which frequently means that you simply never close it
I would stick with the singleton SQLiteOpenHelper (over a singleton SQLiteDatabase), but either should work
Luca
ok
Mark M.
if anyone has a question, go ahead
Luca
A service which use "startForeground" will still need a partial wake lock to avoid that the cpu go to sleep?
4:35 PM
Mark M.
yes
startForeground() gives the service foreground priority, but it has no effect on when the device goes into sleep mode
Luca
ok, i'm already using your wakefulintentservice plus startforeground :P
Mark M.
that should work just fine
Luca
do you have some suggestions to view documents like doc, docx, xls and xlsx? the iOS web view handles a lot of them :/)
Mark M.
let a third-party app handle them
and, if queryIntentActivities() turns up no possible matches, prompt the user to install one
Luca
i can't because are private files Q_Q
4:40 PM
Mark M.
then I cannot help you
Luca
ok i think that only way is using something like apache poi and docx4j to convert documents to html
Mark M.
I would convert them on the server and download the HTML
and then consider PDF, as there are a variety of PDF-viewing libraries, open source and commercial
I have no idea if there is a library for viewing Microsoft files
Luca
ok thank you for your help
bye all!
Mark M.
you are very welcome!
4:45 PM
Mark M.
if anyone has any questions, chime in
4:50 PM
Jeff
hi Mark
I have a question
Mark M.
go right ahead!
Jeff
On a Droid 3, I periodically get the following error, but it doesn't happen on other phones. I'm not too worried but would like your thoughts:
IInputConnectionWrapper(18141): getExtractedText on inactive InputConnection
then I get 17: W/IInputConnectionWrapper(18141): beginBatchEdit on inactive InputConnection
Mark M.
well, that second one is a warning (W/)
Jeff
apparently, the InputConnection is the bridge between the Java code and the system's character reading
they are both warnings - sorry I said error
Mark M.
it's the bridge between the app and the input method editor
devices have a habit of being chatty in odd places, as device manufacturer developers leave Log calls lying around
unless you have symptoms beyond the warnings, I'd ignore them
Jeff
but it requires hitting the back button sometimes
Mark M.
what is "it"?
Jeff
the EditText field won't accept input
BUT, that only occurs with the virtual keyboard. the physical keyboard works fine always
Mark M.
when you say it happens "periodically", I take it that you cannot reliably reproduce the error?
4:55 PM
Jeff
not reliably
Mark M.
still feels like a device bug
Jeff
the thing I like about the droid 3 is that it is the least robust phone I test on
so if it works on a droid3, it generally works
Mark M.
"least robust" -- how polite! :-)
Jeff
OK - I will leave it as device bug - Thanks!
Mark M.
anything else that I can help you with?
5:00 PM
Mark M.
well, that's a wrap for today's chat
the chat transcript will be archived at http://commonsware.com/office-hours shortly
have a pleasant day!
Luca
has left the room
Jeff
has left the room
Mark M.
turned off guest access

Thursday, September 5

 

Office Hours

People in this transcript

  • Aditya
  • Alex
  • Jeff
  • Luca
  • Mark Murphy