Pass data between activities

Steps of passing data between activities :


  1. Open visual studio 2015 and add a new project.
  2. Create a blank android application from application templates.
  3. After creating the project right click on the project root folder.
  4. Add the new item from the item templates.
  5. Choose the Activity and rename it as Second Activity.
  6. Go to the MainActivity.cs page and write the below code on button click event :


           var intent = new Intent(this, typeof(SecondActivity));
            intent.PutExtra("_screenName", "Xamarin");
            intent.PutExtra("_moduleId", "1234");
            intent.PutExtra("_lattitude", "30.2525478");
            intent.PutExtra("_longitude", "70.254789");
            StartActivity(intent);

Now open the Second Activity and write the below code :

            protected override void OnCreate(Bundle bundle)
            {
                  base.OnCreate(bundle);
                  var ScreenName=Intent.Extras.GetString("_screenName");
                  var ModuleId= Intent.Extras.GetInt("_moduleId");
                  var Lattitude= Intent.Extras.GetDouble("_lattitude");
                  var Longitude= Intent.Extras.GetDouble("_longitude");
             }




No comments:

Post a Comment