1

通常,如果我想开始一项新活动,我可以使用

StartActivity(typeof(foo));

这可以。

我也可以设置一个意图

Intent i = new Intent(this, typeof(foo));
StartActivity(i);

问题是这样的。我有 Activity A。这会触发 Activity B。但是,我需要在使用 PutExtra 后触发 Activity B。如果我做

Intent i = new Intent(this, typeof(ActivityB));

当我在 Activity 中定义一个新的 Intent 时,monodroid 会很恼火。

有没有办法做到这一点

(伪代码)

[Activity]
public partial class A
{
   protected override void OnCreate(Bundle savedInstance)
   {
       SetContentView(Resource.Layout.layout);
       Button btnClick = FindViewById<Button>(Resource.Id.btnClicky);
       btnClick.Click += new EventHandler(button_click);
   }

   private void button_Click(object s, EventArgs e)
   {
       Intent i = new Intent(this, typeof(B)); // <- gets annoyed
       i.PutExtra("foo", 1);
       i.PutExtra("bar", true);
       StartActivity(i);
   }
 }

这里的任何帮助将不胜感激。

PFJ

4

1 回答 1

0

看起来我需要添加一个在其他地方不需要的 using。

感谢您的回答,很抱歉延迟回来:)

保证将来,我会确保事情更清楚。

于 2012-07-01T16:17:57.470 回答