I have a requirement, whereby when a user clicks a button, then an object needs to be observed. When the user clicks that button again, the observation stops.
My initial thought is to have the button bound to a method in the activity using the onClick="myMethod"
in the layout file.
When this method is invoke it will call startService()
which starts observing the object. By this I mean it registers the service as an observer.
When the button is clicked for a second time, it calls the stopService()
method which un-registers the service as an observer.
My thoughts for using a service is so the observation; and subsequent actioning is taken off the UI thread. Is this a reasonable approach or is there something in the Android SDK that could do this easier?