Update sample NSD app to work reliably with current Android

Change the management of NSD Listener objects to one which ensures
that each Listener will be used for only one NSD service request at
a time (as the APIs were intended to function).  Listeners are now
allocated in a "lazy" on-demand way, rather than having one Listener
of each type allocated at application startup time.  When the Register
or Discover button is clicked, any existing Listener request of that
type will be canceled and the Listener discarded (avoiding the need
to wait until the Listener callback has been completed), and a new
Listener will be allocated.

Moves code around in the application-lifecycle callbacks to reflect
the current Android lifecycle.  Doing important things like
unregistering NSD services should not be done in the onDestroy()
callback, as there is no guarantee that the app won't be killed
before this callback is invoked.  This can lead to "zombie"
NSD registrations in KitKat.

Adds additional lifecycle logging.

Pass 2 - fix typo, clean up trailing whitespace

Pass 3 - fix onStart/onRestart mismatch

Bug: 13512512
Change-Id: Ic164110759204b27d8a14376777b593ebe1865fa
3 files changed