Android: various bug fixes to prevent NullPointerExceptions