简体   繁体   English

使用Xamarin的Android中“ savedInstanceState”和“ bundle”之间的区别?

[英]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. 我开始使用Xamarin,并且已经看过教程,并在互联网上寻找了针对该问题的具体答案,但是并不幸运。

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: 当我使用VisualStudio选择Xamarin C#Android应用程序创建新项目时,它将自动使用以下代码创建MainActivity.cs:
代码_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: 然后,我添加了一个名为Activity1.cs的新活动(右键单击项目,添加,新项目,活动,添加),但是在此新活动中,Xamarin自动生成的代码是不同的:
代码_2

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

Why is "bundle" replaced by "savedInstanceState"? 为什么将“捆绑”替换为“ savedInstanceState”? What does change if I put "bundle" in Activity1 or vice-versa? 如果我在“活动1”中放入“捆绑包”,反之亦然,该怎么办?

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. bundlesavedInstanceState只是参数的名称,因此它们之间没有区别。 In C# parameter names does not matter. 在C#中,参数名称无关紧要。

Here is a description of the parameter from Xamarin documentation that is passed to OnCreate method: 这是Xamarin文档中传递给OnCreate方法的参数的描述:

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). 如果活动在先前关闭后正在重新初始化,则此捆绑包包含它最近在Activity.OnSaveInstanceState(Bundle)中提供的数据。 Note: Otherwise it is null. 注意:否则为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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