Wednesday, May 25, 2011

Answers to Unanswered Questions from the I/O Protips Q&A

There's never enough time for Q&A at the end of an I/O session - particularly when the session is immediately followed by lunch. In an effort to remedy this, here are the answers to most of the questions that were entered onto the Moderator page for my Android Protips talk.
    Eclipse is a wonderful development tool. However sometimes it is clunky. Generic error messages, mysteriously build problems solved by quitting & relaunching, etc. Do you ever get frustrated with Eclipse? Do you have any tips of working with Eclipse?
I do! Almost as much as I was frustrated by Visual Studio in a previous life spent writing C# Winform GUIs. I don't have any specific tips beyond the things that work with mode IDEs. Frequently restart and make sure you're using the latest stable build along with the latest version of the ADT.
    Do you have any tips for working with SQLite databases through eclipse? At the minute I rely on external tools to view data that is in the database on the phone to debug problem. This means manually copying it off the device. Any tips?
You can use the sqlite3 command line tool to examine SQLite databases on the phone. It's not built into Eclipse but might save you the extra work of pulling the database off the device first.
    Do the developers at Google use any hardware emulators to speed up development. If so, can you please recommend some. The soft emulator is too slow.
Unfortunately not. Generally we'll be working towards the release of the new platform on a given piece of hardware, so the internal teams will use that rather than an emulator where appropriate / applicable.
    Will there be a faster Android device emulator anytime soon?
Yes! Check out this session on Android Development Tools for a preview.
    Is there a suite of AVDs for Eclipse that emulate actual devices?
Some manufacturers make AVDs available for actual devices (I believe Samsung provide an AVD for the 7" Galaxy Tab). Generally speaking, no - there's no central repository or suite of all actual device AVDs.
    Will there soon be a legitimate way to replace the Android lockscreen (with a lockscreen application)?
Due to the security implications, I'm not aware of any plans to make the lock screen (or in-call screen) replaceable.
    You mentioned better not to loose your signing key. But how to update your app, when your certificate expired?
For now, certificates used to sign apps launched in the Android Market need to expire after 22 October 2033. We'll have a solution for replacing these certificates in place well before 2033 :)
    What's the recommended way to implement a horizontally scrolling, virtualized list?
No simple answer here as it depends on the kind of data you're displaying, how long your list is, and what the best user experience would be. There are some good articles online (including this answer on Stack Overflow) that explain how to create a virtual list in a ListView, but you can use a similar technique within a Gallery or even a HorizontalScrollView to achieve a horizontal virtualized scrolling list.
    Are Shared Preferences the bast way to store small piece of data?
It depends on what kind of small data you're storing. Shared Preferences are the best way to store user preferences and Activity / Application state information.
    A view from one app needs to be updated by another app. Can't use the widget paradigm, is there any other way?
This depends on a number of factors. Are both apps written by you, or is one a third party? How dramatic are the changes? New layouts or changed text in a TextView?

Generally speaking, the best approach is likely to be a Broadcast Intent. You can package the data that will be used to update the View in the "other" app by including them as extras. The "other" app simply registers a Broadcast Receiver that listens for the Intent, extracts the data, and updates its view accordingly.
    How would you test/optimize the apps that are not meant for the Android Market?
The principle of using Analytics for tracking bugs and doing A/B testing works just as well internally as it would on apps that will launch in Market. The biggest difference is distribution. Given the ability to side-load apps onto most Android devices, I'd most likely setup an internal website that would host the APKs you want to distribute for the Beta test.
    How can we know if a certain service is already running?
You can bind to a Service using bindService without starting the Service. The Service Connection you pass in to bindService will notify you using its onServiceConnected and onServiceDisconnected handlers when the Service starts and stops. You can use those callbacks to set a variable within your code to check if the Service is running at any given time.
    Is there any option to backup the default SharedPreferences via BackupManager? Do I have to use the packagename?
The default SharedPreferences file getSharedPreferences uses the Activity's class name as the preferences name.
    Is there a way for accessories to "push" an embedded app or service package to the device so that specialized services for certain types of accessories will be able to automatically add functionality to the device when connected?
As part of the process of starting the device in accessory mode, you send identifying string information to the device. This information allows the device to figure out an appropriate application for this accessory and also present the user with a URL if an appropriate application does not exist. It won't install the package for you, but it will prompt the user to download it.
    Just to make sure, now we can send requests to the devices in order to update the info, instead of having the refresh intervals?
That's right, you can use Cloud to Device Messaging to ping a device when it needs to perform an update.
    When will we have a UI Builder that is par to what we get for iPhone?!
Check out this session on Android Development Tools for a preview of some of the cool stuff the tools team have been working on.
    Can you describe your video and control hookup for your android tablet?
I wrote a blog post that describes the video and control hookup I used to do my presentation using a pair of Motorola Xooms.

Monday, May 23, 2011

My Attitude Towards Piracy of My Book

The short answer: I am against it.

Lest I be accused of bias, that goes for every book - not just the ones that result in a couple of bucks landing in my pocket.

The long answer

I was surprised recently when asked via email what my attitude was towards piracy of my book, and if an online donation might work as a "last resort" way for pirates to show their appreciation for my work.

For the record, I am a big supporter of making my book available in as many formats as possible. That's why I'm impressed that Wrox books are now available on Kindle, Google Books, Safari, and PDF eBooks. I get a royalty no-matter where you buy it from, so if you want a copy pick wherever offers the cheapest price for the format you prefer.

I'm also against DRM - I believe that DRM does nothing to prevent piracy while annoying the folks who legitimately paid for the content - so I was also thrilled with Wrox's decision to make their eBooks DRM free.

Your book is expensive: Do you have a donate link anywhere to show my appreciation but save a few bucks?

I can't speak for anyone else, but I don't write my books for the money. The advance and royalties go some way to compensating for the significant time and effort it takes to get the books written - but for me at least, it's not going to make me rich or let me give up my day job.

More importantly I don't write in a vacuum. Books cost money to make. I'm not talking about the paper, printing, and transport costs, I'm talking about all the people who were involved in making my book the best it could be.

There are 17 people on the "Credits" page for Professional Android 2 Application Development. They are not vanity credits. As an example, the following folks are the ones on that list who I had direct, repeated email contact with over the course of writing the book. Apologies to those I left out - they are equally important to the process.
  • Scott Meyers (Acquisitions Editor) suggested I write a second edition and shepherded it through the process.
  • William Bridges (Project Editor) made sure I handed in chapters on something resembling a schedule (without him I'd still be working on the 1st edition), as well as dispensing invaluable advice on everything from book and chapter structure to clarity and semi-colon use.
  • Milan Shah (Technical Editor) reduced the number of bugs in my code.
  • Sadie Kleinman (Copy Editor) corrected my comma use, spelling errors, grammatical issues, and generally ensured I didn't embarrass myself.
  • Mary Beth Wakefield (Editorial Manager) kept it all together when things got chaotic.
  • Kyle Schlesinger (Proofreader) ensured nothing slipped past us during the many edits and revisions before it went to print.
  • Michael Trent (Cover Designer) gave us the awesome Terminator cover (image by Linda Bucklin).
  • Robert Swanson (Indexer) provided a way to find things without a photographic memory.
  • David Mayhew (Marketing) made sure it was available from wherever people wanted to buy it.
These folks are an absolutely essential part of the writing process, and they don't work for free. Nor should they. There is a really simple way to show your appreciation for all the people involved in writing a book. Buy it.

Sure, but I need to know what the book teaches for my job / class, but I don't have the money to buy it.

Good news! You don't have to! At the risk of hurting my own sales, you don't need to buy my book to learn how to develop Android apps. I mentioned this during my Android Protips talk: Google aren't trying to keep this information a secret. There's a huge amount of information available online including:
Many people find the structured, consistent, and guided form of a book to be a great way to learn new material. Others find books a more useful reference while working. If you're one of those people, and you want to be able to continue using books in such a way, buying them is the only way to help ensure that will happen.

What are your thoughts on 2nd hand books and libraries?

Bring them on! I've probably bought 1,000 books in my life - of which more than half are 2nd hand, and I've probably borrowed a few hundred from libraries too.

Electronic books introduce new challenges to the 2nd hand book market and libraries. I'm firmly on the side that says that the rights we have with paper books should be mirrored in the electronic publishing age. If you're done with a book you should be able to sell it, loan it, or give it away without restriction.

If everyone downloads pirated PDFs of books instead of buying them, publishers will stop publishing them.

Without a publisher many books won't get written or released. I don't have the time, money, skills, or inclination necessary to produce a book of sufficient quality on my own. I need the 17 people on the credits page (and several more besides) to publish each new book or revision.

Writing isn't my livelihood, so as an author the end of publishing would be a serious disappointment, but I'd just stop writing and get on with my day job.

As a reader? I can barely imagine a future so grim.

Monday, May 16, 2011

Android Protips: Where to Download the Slides and Code Snippets

For those of you who want to take a closer look at my Android Protips session for Google I/O, you can now enjoy the video, slides, and code snippets in whichever format you prefer:
One of the nice things about SlideShare is that it lets you embed slideshows into your blog post:

I plan to do a series of more blog posts that dig into some of the topics I cover in the presentation in more detail. Where do you guys think I should start?

Android Protips at I/O: The Session Video (and How I Presented It)

[Update 16/May: Reposted after Blogger outage]
[Update 2: Working links to the sessions slides are available from here]

Another Google I/O, another jam-packed Android session room. This year they nearly doubled the room capacity for the main Android track making space for 1,000 seats. That still wasn't enough though - once again people were sitting on the floor and lining up to get in.

Android Protips: Advanced Topics for Expert Android Developers

After delivering my Android Best Practices for Beginners for the better part of last year, I was really excited to take things up a notch and deliver some real advanced content. To push things one step further, I presented my session using a pair of Xoom tablets. More on that after the video.

The awesome video content was created for me by an old friend of mine (he's still young, but we've been friends since high school) pandamusk - thanks panda!

How did you do that?

There were a lot of questions on Twitter asking:
  1. What app did I use to do the presentation using an Android tablet
  2. How did I live tweet my own presentation in real time?
  3. How did I not re-tweet everything when the tablet rebooted?
I'm an engineer so (of course) I took this as an excuse opportunity to write an app that does the former and built in functionality to do the latter (and come on — you think I didn't consider the case of having to restart? Please.)

How does it work?

One app, running on two tablets, both running Android 3.1 (with USB hostmode support) connected via Bluetooth.

Tablet one was wired up with HDMI out and a USB-connected clicker let me transition between slides. I added a "finger paint" View with a transparent background on top of the ImageView that displayed each slide which let me do the real-time annotations.

A second device (out of sight on the lectern) showed me my "Speaker View": My speaker notes, the current / next slide preview, my pre-written live tweets, and a countdown timer.

The two devices were paired and connected over Bluetooth, with the speaker view tablet set up as a slave to the presentation device. Whenever the display tablet transitioned slides, it transmitted the current slide to the speaker view tablet. It works the other way around too, so I can transition slides on the speaker view and have the live view update accordingly.

The tweeting happened on the speaker view tablet based on slide transitions (with a button for me to disable it if — for example — I had to restart half way through). I connected this one to a wired ethernet connection using a USB to ethernet dongle to avoid the notorious conference wifi syndrome.

I've got a bunch of ideas I'd like to incorporate (particularly around remote viewing), but ran out of time before I/O to get them implemented.

Can I Get the App? Can I See the Source?

Yes and yes. I need to make a few improvements before I release it on the Android Market and I need to refactor and tidy the code before I open source it. In the mean time I'll do a couple more posts the go into more detail on how each of the components work. Stay tuned.

Tuesday, May 10, 2011

How to Get Your Android Protips

I/O is always a great couple of days, and after last year's jam-packed Android room they've doubled our capacity and given us space for 1,000 folks in the audience. As if that wasn't enough, we're also live streaming the Android (and Chrome) sessions for your viewing pleasure.

What Am I Presenting and How Can You Watch?

I'm presenting Android Protips: Advanced Topics for Expert Android Developers at 11:30am PDT in room 11 up on the top floor (next to the keynote room) for those of you lucky enough to be at I/O in person.

If you're not here, you can still watch my session live as it's going to be live streamed across the intertubes (Stay tuned: that page will update when I/O starts in a few short hours).

If you are planning to tune in, that's 7:30pm BST and an ungodly 4:30am on the East coast of Australia.

If you've got questions, and won't be in the audience, you can pose them (and vote for others) on the session's moderator page.

I'm also going to try live-tweeting my own presentation using an Android app I've been working on for presentations (more on that later).

Once I'm done, the recorded video and slides will be available on the Android Protips session page. I'll also post a link to the code snippets for your copy/paste pleasure.

If You Just Can't Get Enough (or You Want to Know How to Avoid Bumping in to Me)

I'm also co-hosting "Web Apps versus Native" on Wednesday afternoon with Michael Mahemoff. Should be a good way to wind down after a long couple of days. When I'm not on stage I'll be hanging out at the Android office hours, so be sure to stop by and say hi!