Office Hours — Today, December 20

Tuesday, December 18

Mark M.
has entered the room
Mark M.
turned on guest access
Marcin
has entered the room
Mark M.
howdy, Marcin!
how can I help you today?
Marcin
Hi Mark
Andrew G.
has entered the room
tunneling
has entered the room
Mark M.
howdy, Andrew and tunneling!
Marcin: do you have a question?
tunneling
howdy howdy
Marcin
yes
Andrew G.
hello
Dec 20
4:00 PM
Marcin
AsyncTask can be cancelled by invoking cancel(boolean) on it
and then checking isCancelled during loadInBackground
is there a similar mechanism in AsyncTaskLoader?
Jan
has entered the room
Jan
Hi everyone
Mark M.
there is cancelLoad() that you can call on Loader
(BTW, howdy, Jan -- be with you in a bit)
Jan
ok
Dustin R.
has entered the room
Marcin
what about cancelLoadInBackground()?
how one should use it?
Mark M.
you don't use it
it really should be named onCancelLoadInBackground()
you override if if needed
the default implementation is an empty method
Marcin
if i use cancelLoad() how should I check for it during loadinbacground?
Mark M.
I have not tried cancelLoad() or cancelLoadInBackground(), and so I do not know much more about them, sorry
Marcin
ok, thanks
Mark M.
(BTW, howdy, Dustin!)
Marcin
thats it from me for now
4:05 PM
Mark M.
OK, Andrew got in slightly before tunneling, so...
Andrew: do you have a question?
Andrew G.
Ok quick one first
tunneling
im just hanging out.. so skip me for now
Dustin R.
Hi Mark, I am a huge fan of your books, I am a former east asian language teacher currently java developer of 3 years looking to write free langauge learning apps. I hope you dont mind the overly general question but what chapters would you recommend I focus on?
Andrew G.
It is generally reccomended that one register a broadcast receiver in onResume and unregister it onPause
Mark M.
um, that *is* pretty general :-)
but, Dustin, I will get to your question in a bit
Andrew: please continue
Dustin R.
ok thank you, take your time ^_^
Andrew G.
How should I handle it if I want to take an action on my registered receiver accounting for screen sleep (which would unregister it)
IIRC wakelocks = bad
Mark M.
can you be a bit more specific about "take an action">
?
Andrew G.
well, I have an inbox which gets push broadcasts from C2DM about new messages
I want it to show that message
Mark M.
is the message purely within the C2DM/GCM payload, or are you having to do additional I/O?
Andrew G.
all in the payload
well sorry that's not ture
true*
not if I have an attachment
which I then d/l separately
Mark M.
OK, for the main message, you can just update the UI, assuming this BroadcastReceiver is registered via the activity by registerReceiver()
you'd then also use DownloadManager or your own IntentService to download any attachments
and, if it is your own IntentService, probably use WakefulIntentService (or the equivalent) just for the download
4:10 PM
Andrew G.
Can an IntentSerice be killed off randomly as well?
Mark M.
um, define "killed off randomly"
Andrew G.
low device memory (just like Activities)
Mark M.
neither activities nor services are "killed off randomly" due to low memory conditions
*processes* can be terminated to free up memory due to low memory conditions
and, yes, processes containing services can be killed off, though that is less likely
you can use startDownload(), if you feel it is warranted, during your download to further increase the odds that you'll be left alone
let me swing through the rest of the group, and I can follow up with you more in a bit
tunneling: do you have a question?
Andrew G.
ok thanks
tunneling
no sir
Mark M.
ah, just hanging out?
no problem
Jan: do you have a question?
Jan
Hi Mark,
tunneling
ya
Jan
Here is my question :
In your "SQLite Database" chapter at the end you write about Async CRUD updates. Later on in the "Contentprovider" chapters you introduce the "new" Loader framework for async queries with content providers. Is there anything new to insert/update/delete in async way on a contentprovider, or do we have to use the "traditional techniques" from the "SQLite Database" chapter using AsyncTask ?
Mark M.
Loader is only for loading
you update a ContentProvider using an AsyncTask or regular Java thread
unless somebody provided utilities to handle that for you
so, for example, my SQLiteLoader offers methods to handle CRUD operations, and handles the threading for you
Jan
OK understood
4:15 PM
Mark M.
but CursorLoader does not, which is why you have to do the async work yourself
4:15 PM
Jan
I'll have a look at the SQLiteLoader, thanks
Can i ask you another question ?µ
Mark M.
yes, but let me get to everyone first
Jan
ok
Mark M.
Dustin: back to your question
is there something in particular about your apps that you are concerned about vis a vis the book coverage?
Dustin R.
capabilities needed: screen draw non roman characters, save all my data in sql lite database, creating fun UI
err
mainly #1
Mark M.
that then boils down to whether or not you have a font with the glyphs you need for the language you want
Dustin R.
screen drawing non roman characters and tehn recognizing them, is there anything you are aware of that does this?
Mark M.
(either the stock font for the device or one you bundle)
oh, wait
when you mean "screen drawing", you mean the *user* drawing them, or *you* drawing them?
Dustin R.
user drawing
Mark M.
oy
the recognition part would presumably fall under OCR, which Android does not natively support, and is a serious resource hog
Dustin R.
I read the legacy titles when they were new but i was curious if there was anything that could support that now days
Mark M.
you might be able to work out a simpler approach, if you are only dealing with individual characters or short strings
(e.g., fuzzy match images)
Dustin R.
yeah that would be another approach
Mark M.
but that too isn't built into Android -- you'd need to find libraries for full-on OCR or fuzzy image matching
with regards to drawing, there's nothing specifically built in for that either
4:20 PM
Mark M.
there are plenty of "sketch" samples out there
and Square had a couple of blog posts about signature capture which might be semi-relevant
doing more in this area is on my to-do list for 2013
Dustin R.
oh great, i look forward to it
Mark M.
assuming that I survive after midnight
tunneling
google "Machine Learning"
Mark M.
tunneling: yeah, that might be part of the mix too, though that is also resource intensive in general
Dustin R.
ah hmm android might not be the best platform for a tool like that
Mark M.
coming up with something that can run on garden-variety phones is going to be a challenge
just due to CPU and RAM constraints
Dustin R.
ok, thank you. i will let you know when i have more specific questions
Mark M.
OK
back to the beginning...
Andrew G.
esp since 'garden-variety' means sad looking Ginerbread phones :P
Mark M.
Marcin: do you have another question?
Marcin
yes
View paste
I have an app with Main Activity A.
I launch the app, and A starts, it invokes AsyncTaskLoader B through LoaderManager
B does three calls to remote server through httpclient and after each call it saves some information to local sql
B should take about 5sec in overall
if I launch the app and then press back before B completes I want B to be cancelled (it should stop updating the db and connect to remote server)
How should I do it properly? When should I close db?
Mark M.
um, beats me
Marcin
"..db and not connect.."
Mark M.
I have never tried using the Loader paradigm for Internet operations
and IMHO it is inappropriate for having it update a database based on loading
Marcin
how would you do it?
Mark M.
a plain AsyncTask or an IntentService
4:25 PM
Mark M.
cancel-ability would have me lean towards AsyncTask
4:25 PM
Marcin
how would you cancel it?
Mark M.
(IntentService tends to better for "fire and forget" approaches)
call cancel()
in your read-the-InputStream loop and such, check to see whether you are cancelled
Marcin
how about db? should i call isCancelled() check before every db operation
Mark M.
possibly
personally, I'd think that if you went to the trouble to download the data, you may as well save it to the database
but, if you're sure that you do not want to do that, check whether you were canceled before running the transaction
Marcin
im with you that since i have the data i should store it
but if app is not running how should i leave db connection?
Mark M.
by definition, the app is running
otherwise, your process is gone, your task is gone, etc.
Marcin
at the moment i have a static ref to db
Mark M.
the general strategy in complex apps is to not worry about closing the database
because there's never a good time to do it
Marcin
and i simply dont close it anywhere
Mark M.
and SQLite handles this well
that's what ContentProviders do
so not closing it, if you do not know when to close it, is (unfortunately) reasonable
Marcin
hmm.. i will try this approach.. Thanks Mark, thats it from me for now.
Mark M.
OK
Andrew: do you have a question?
4:30 PM
Andrew G.
I do, about the ViewPager
I load a bunch of images into it that are downloaded one by one via IntentService. At the begining I set a 'placeholder' image so the user can flip through all of the images that *will* be there
As I'm notified via PendingIntent that the image is ready, I'd like to replace those placeholders
What I'm finding is that I can't do that reliably
if the user is viewing a placeholder when I get that callback, it will not be updated via notifyDatasetChanged
Mark M.
why are you using notifyDataSetChanged()?
why not just update the ImageView of the current page?
Andrew G.
I change the drawable in the underlying set
well, I had tried that and it gives *changes* but just goes blank
doesn't redraw with new content
Mark M.
if you update the ImageView, I feel pretty darn sure that it will redraw
Andrew G.
ugh well hopefully the problem is not the fact that I'm using a third-party wrapper around ImageView
GestureImageView to support zoom/pan
Mark M.
hmmm... that's not out of the question
the implementation might have made assumptions about the immutability of the image
Andrew G.
Guess I could switch to vanilla and see if I get the update
Mark M.
you might consider making the placeholder be a regular ImageView, load your real image into the GestureImageView, and toggle visibility
4:35 PM
Mark M.
(assuming GestureImageView and replacing the image winds up being the sticking point)
Andrew G.
resource intensive no?
Mark M.
assuming that your placeholder is a resource, it shouldn't be too bad
only one copy of that bitmap will be in memory
Andrew G.
so the ViewPager would be paging through ViewFlippers?
flipping between the imageView and GestureImageView
Mark M.
ViewFlipper?
no, I meant toggle visibility
setVisibility(View.GONE)
setVisibility(View.VISIBLE)
Andrew G.
isn't the VIewFlipper the proper way to do that?
Mark M.
well, you could, but a FrameLayout works quite nicely too
Andrew G.
alrighty I'll give it a whirl thanks
Mark M.
ViewFlipper would be if you wanted an animated effect, or automatic changes, or something
Jan: do you have a question?
Jan
Yes
Mark M.
(and, tunneling, if you have one at some point, let me know and I'll add you back into the queue)
Jan
What is the best way to have a bidirectional sync between the local SQLite DB of many mobile android phones with a central SQL server. I know about the SyncAdapter, but one still has to implement the sync algorithm himself. Apart from Microsoft Sync Framework Toolkit, is there any good sample or libary that offers reliable sync ?
tunneling
k
Mark M.
on the server side, I haven't a clue
I haven't touched Microsoft server products in earnest in over a decade
and the server side will dictate terms for what you do client-side
Jan
What about non-MS products ?
Mark M.
plus, I haven't played with SyncAdapter much yet (on the relatively-early-in-2013 to-do list)
tunneling
has left the room
Mark M.
bi-directional sync will not be much fun
Jan
Great, looking forward to it, because I cannot imagine I'm the only one with this problem
Why not ?
Mark M.
my usual solution is to find something that does it for me (e.g., CouchDB)
if there are updates to the same rows on both sides, dealing with merge conflicts may be troublesome
and fairly scenario-dependent
4:40 PM
Mark M.
but, I'm sorry, I'm just not well versed in this area at the moment
Jan
Do you know of any samples with CouchDB ?
Mark M.
specifically with Android, no, though my understanding is that CouchDB offers sync between the Android edition and a regular CouchDB server
Jan
I see, no problem ... i wait for Q1/2013 :-)
I'll have a deeper look in CouchDB in meanwhile. Thanks
Mark M.
obviously, I need to refine my definition of "relatively early"... :-)
Dustin: do you have another question?
Dustin R.
Care for another general one?
Mark M.
sure
Dustin R.
I understand from your book about data passing in UI's with widgets and all, do you know any tutorials about making them graphically appealing?
Mark M.
well, everyone has their own definition of "graphically appealing"
at least 90% of which I find unappealing
the guts lie in the styles and themes
but there is little documentation about all the possible levers that you can pull and switches that you can throw in terms of styling the stock widgets
let alone the specific mechanics (e.g., what sorts of images need to be created)
there's a variety of blog posts floating around that discuss the topic
but I don't exactly have their URLs at my fingertips
Dustin R.
okay I can google them
4:45 PM
Mark M.
personally, particularly with the holographic theme that debuted with Android 3.0, I'm fairly happy with the look of the stock widgets and don't mess with it, except perhaps for styling the action bar a bit using the Action Bar Generator
Dustin R.
OKay i will look up holographic theme
that would be really helpful
Mark M.
for simple color changes on widgets, for Android 3.0+, use the Holo Colors Generator: http://android-holo-colors.com/index.php
Dustin R.
and for pre 3.0 devices I will just have to set an older theme?
Andrew G.
!
Mark M.
there is the HoloEverywhere project, which is trying to create a theme and assets that allow Holo to work on older devices
Andrew G.
wish I knew about that last week
Mark M.
(Andrew: subscribe to the newsletter! I mentioned it a few months back)
I have not tried HoloEverywhere, personally, so I cannot vouch for how complete it is or how well it works
Dustin R.
Great I will chekc it out. For some reason people show a lot more interest in apps based off looks not content
Andrew G.
ha. Well I think you should still have both (from a person who may be a future consumer of said app)
Mark M.
Marcin: do you have another question?
Marcin
yes
4:50 PM
Marcin
taking under consideration your skill level, are you considering (or maybe already have done so) creating and monetizing some apps?
just curious
Jan
has left the room
Mark M.
I have written some apps under contract
any apps that I would write separately would not be "monetized" in the form of paid apps, in app purchases, ads, etc.
as I am just not a huge fan of those business models
Dustin R.
a true open source believer?
Marcin
do you plan on realising your own apps?
Mark M.
more that I am not a mass-market marketer
Marcin
somewhere soon 2013 maybe?
Mark M.
Marcin: I am not planning on writing an app for the sake of writing an app
I have the book in APK form (and have some improvements to make to that this weekend)
my plans for 2013 may involve apps, but they are ancillary aspects of a larger strategy
which is not exactly fodder for an office hours chat
Andrew G.
May I throw in one last technical question?
Marcin
thanks Mark, all devs that i have met in my limited experience with Android have this plan of creating/monetizng an app within a year.. even if they work on contract for someone else
Mark M.
Andrew: go ahead
Andrew G.
I'm looking to enforce full disk encryption on all devices that install my app. I admit I've not yet checked the book on this but do you cover PolicyManager in any great depth? The offical docs are rather confusing.
4:55 PM
Mark M.
I cover the device admin APIs in the book, and I mention the full-disk-encryption bits
Dustin R.
Thank Mark, keep up the good work. I am out to get busy developing
Mark M.
I don't have a sample specifically for full-disk-encryption, though
Dustin R.
has left the room
Andrew G.
np. Just being able to enforce anything would get me going
so I should be looking for "Admin API" not "PolicyManager"?
Mark M.
the Device Administration chapter is 1287-1296 in the current edition of the book
the class is DevicePolicyManager, IIRC
Andrew G.
great - thanks
Mark M.
we are running out of time -- any final questions?
Andrew G.
that's all for me
Hope you both enjoy the upcoming apocolypse
Marcin
im out of questions, Thanks Mark
going to get my last supper
Andrew G.
heh
Mark M.
I have this vision of Miracle Max from _The Princess Bride_ saying "have fun! enjoy the apocalypse!"
:)
Marcin
hah
night night guys
Andrew G.
has left the room
Marcin
has left the room
Mark M.
turned off guest access

Tuesday, December 18

 

Office Hours

People in this transcript

  • Andrew Gibel
  • Dustin Robison
  • Jan
  • Marcin
  • Mark Murphy
  • tunneling