Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Google Play Services Connecting to Play Services Integrating GoogleServicesHelper

syed ehteshamuddin
syed ehteshamuddin
969 Points

When does onConnected, onDisconnected methods declared in Interface are triggered ?

I'm trying to trace the interface methods to see when are these methods actually triggered, my understanding is implementation of onConnected is called when onConnected method of Google API is called and same for onDisconnected, correct ? or am i missing something ?

1 Answer

Boban Talevski
Boban Talevski
24,793 Points

That's pretty much correct, but not exactly for onDisconnected. We have our ListingAdapter implementing that GoogleServicesListener interface with onConnected and onDisconnected methods, so these methods are implemented in the ListingAdapter class.

Since we have the adapter as a class variable in the GoogleServicesHelper class (the listener object), we just call onConnected on that listener object whenever Google API's version of onConnected gets triggered. As for onDisconnected, we call it on the listener object as well, but in multiple scenarios - whenever we want to tell our adapter that we are not connected, so the adapter acts accordingly.