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 Android Activity Lifecycle The Activity Lifecycle Retrieving Instance State

Jvalant Dave
Jvalant Dave
4,483 Points

Challenge 2 of 3 for the following question?

"In the onSaveInstanceState method, save the number 10 to the bundle."

Not really sure what to do here. In the previous challenge, I put:

private static final String KEY_USERENTRY = "KEY_USERENTRY";

Not sure how this applies to the next question since it asks for a number instead of a string.

1 Answer

andren
andren
28,558 Points

When you save something to the bundle it requires two arguments, a key (which is essentially a label for the data) and the actual data you want to save, the key is always a string regardless of what type of data you are saving to the bundle.

You were asked to create a KEY_USERENTRY variable because it is a common convention to store bundle keys as final variables in order to make it less likely that you make typos when you reference this key later on in the code.

That is how the first task relates to the second, as to how to solve the second task that is something that is shown off in the video that precedes the challenge, but I'll give you a hint, the bundle (which can be accessed though the outState variable) has a method called putInt, that takes a key as the first argument and an int as the second, and saves it to the bundle.

That info should help you solve the task.