简体   繁体   中英

Difference between “savedInstanceState” and “bundle” in Android with Xamarin?

I'm starting to use Xamarin and I already saw tutorials and looked over the internet for a specific answer to this question, but with no lucky.

Here's the question.

When I create a new project with VisualStudio choosing a Xamarin C# Android application, it automatically creates a MainActivity.cs with this code:
代码_1

Note this code:
protected override void OnCreate(Bundle bundle)
and
base.OnCreate(bundle);

Then I added a new activity (right click on the project, Add, New item, Activity, Add) called Activity1.cs, but here in the new activity the code automatically generated by Xamarin is different:
代码_2

Note:
protected override void OnCreate(Bundle savedInstanceState)
and
base.OnCreate(savedInstanceState);

Why is "bundle" replaced by "savedInstanceState"? What does change if I put "bundle" in Activity1 or vice-versa?

Thanks a lot to anyone can help me, and sorry if it seems a silly question.

bundle and savedInstanceState are just names of the parameter so there is no difference between them. In C# parameter names does not matter.

Here is a description of the parameter from Xamarin documentation that is passed to OnCreate method:

If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in Activity.OnSaveInstanceState(Bundle). Note: Otherwise it is null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM