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
onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.
Basically Bundle class is used to stored the data of activity whenever above condition occur in app. onCreate() is not required for apps. But the reason it is used in app is because that method is the best place to put initialization code.
onCreate(Bundle savedInstanceState) Function in Android: When an Activity first call or launched then onCreate(Bundle savedInstanceState) method is responsible to create the activity.
What is the savedInstanceState Bundle? The savedInstanceState is a reference to a Bundle object that is passed into the onCreate method of every Android Activity. Activities have the ability, under special circumstances, to restore themselves to a previous state using the data stored in this bundle.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With