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

gregory stocker
gregory stocker
3,520 Points

Why are things like listeners called inside the OnCreate method? Isn`t OnCreate only called when the app first launches?

Is OnCreate continually called or is it just called once? How does it track a listener if it is only called when the app first opens up? Is it like a while loop that keeps checking? The way I think of it it would only work if you had an onClickListener setup and you clicked it right as it was created, but that`s obviously not the case.. What am I missing about how the android lifecycle works. When the app is running what state is it in that is constantly checking things? I hope this question makes sense thanks anyone in advance.

1 Answer

It is only called once when you start the application. It doesn't track the listener. The listener is an object that is created when the application starts if it is under the OnCreate method. A listener is not a loop, it waits for an input from a user. The app doesn't constantly check things. It waits for the users to do something with it. A user can pause, stop, destroy, restart an application, or continue using it. These are all part of the Android lifecycle. I suggest that you read this article http://developer.android.com/training/basics/activity-lifecycle/starting.html