1
votes

Using XamarinStudio and below code base on the Sample in the tutorial. Here the questions.

  1. Do I need to generate the AndroidManifest from the Project Option> Android Application when testing the App ?

Why there is no data passing over even I have generated an AndroidManifest , the code :


---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";

        }

    }

Thanks

1
Do you get to see "Data not available" in the label or nothing at all?jHogen
yes. I get "Data Not Available"MilkBottle

1 Answers

0
votes

Ok I found the problem when I remade the project myself. The problem lies in this piece of code:

var second = new Intent(this, typeof(SecondActivity));
second.PutExtra("FirstData", "Data from FirstActivity");
StartActivity (typeof(SecondActivity));

What happens is that you make an Intent with the right data. But you start a new activity without that data. To fix it change the code to this:

var second = new Intent(this, typeof(SecondActivity));
second.PutExtra("FirstData", "Data from FirstActivity");
StartActivity(second);`