newIntent method

Hello! There’s a great answer (Question about newIntent method) for why it’s smart to implement this method.

My question is why is this method in the CheatActivity and not in the QuizActivity? I tested my code now and the app runs the same if newIntent() is a non-static method in QuizActivity.

Since QuizActivity is the main activity (the activity that is started when you tap on the app icon) there is no place in the code where you explicitly create an intent to start QuizActivity. When you tap on the app icon, the operating system is going to create an intent in its own way and will not call a newIntent method.

Hi antoniorosario,

“There is no reason for QuizActivity, or any other code in your app, to know the implementation details of what CheatActivity expects as extras on its Intent. Instead, you can encapsulate that work into a newIntent(…) method.”

As the above things mentioned in this book, the implementation details of the method newIntent() should be encapsulated in class CheatActivity. QuizActivity or any other activity doesn’t need to implement its own newIntent method for the same CheatActivity respectively.