Create your account

Already have an account? Login here

Note: By joining, you will receive periodic emails from Coursetro. You can unsubscribe from these emails.

Create account

99. Save the State of our custom widget

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video shows how to save state of our custom view in Android using a Bundle. After the user selects a date and rotates the screen, the custom date picker widget should be capable of showing the previously selected date.Override the onSaveInstanceState method which is called prior to rotation where you get a chance to save the values for date, month and year using a Bundle object and its putInt method. Use the onRestoreInstanceState which is called after the rotation is complete where we retrieve the Bundle which we saved previously and call getInt to retrieve the date, month and year values once again.

Course Cirriculum