Stole code from AndroidExample.