Can you please explain onCreate and Bundles?

Mike picture Mike · May 22, 2010 · Viewed 9.4k times · Source

I have been looking it up and I just cant seem to wrap myself around the onCreate and Bundles. I understand that the onCreate is called when the program starts but its how the Bundles get passed around and how they are pertinent. Can anyone try to put this into plain english because I cant seem to find it well described.

Thanks

Answer

Macarse picture Macarse · May 22, 2010

The Bundle in the onCreate method should hold the state of you activity before it was killed.

Simple example, when you change the orientation of your device your activity is recreated. Imagine the user is filling a long form and he/she accidentally changes the orientation. When the app gets restarted all data entered will be lost unless you persist that information. One possibility is using a Bundle.

If you want to know how to use it, I would recommend that you read this question.