使用XamarinStudio及以下代码基于本教程中的Sample。这里是问题。
为什么没有数据传递,即使我已经生成了AndroidManifest,代码:
---Activity 1 [Activity (Label = "HelloMultiScreen", MainLauncher = true,Icon = "@drawable/icon")] public class FirstActivity : Activity { int count = 1; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); //Use UI created in Main.axml SetContentView (Resource.Layout.Main); var showSecond = FindViewById (Resource.Id.showSecond); showSecond.Click += (sender, e) => { var second = new Intent(this, typeof(SecondActivity)); second.PutExtra("FirstData", "Data from FirstActivity"); StartActivity (typeof(SecondActivity)); }; } } ---Activity 2 [Activity (Label = "SecondActivity")] public class SecondActivity : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Create your application here SetContentView (Resource.Layout.Second); var label = FindViewById (Resource.Id.screen2Label); label.Text = Intent.GetStringExtra("FirstData") ?? "Data not available"; } }
由于
答案 0 :(得分:0)
好的,当我自己重新制作项目时,我发现了问题。 问题在于这段代码:
var second = new Intent(this, typeof(SecondActivity));
second.PutExtra("FirstData", "Data from FirstActivity");
StartActivity (typeof(SecondActivity));
您会使用正确的数据制作Intent。但是,如果没有这些数据,您就会开始新的活 要修复它,请将代码更改为:
var second = new Intent(this, typeof(SecondActivity));
second.PutExtra("FirstData", "Data from FirstActivity");
StartActivity(second);`