Passing values between Activities using MonoDroid
Been doing some work in MonoDroid and found that I needed to pass a user entered value from on Activity to another Activity in MonoDroid. Here's how I did it.
In my sending Activity, I need to take some user user entered data and send it to my second activity. Here is the code:
string UserId = Convert.ToString(et.Text);
if (!String.IsNullOrEmpty(UserId))
{
Intent i = new Intent();
i.SetClass(this, typeof(CustomList));
i.AddFlags(ActivityFlags.NewTask);
i.PutExtra("TwitterId", UserId);
StartActivity(i);
}
In this code, I have called .PutExtra and passed it with a key. In this case, I am passing a Twitter id. In the code that is receiving the data, the code to retrieve the Twitter id is:
string twitterId = Intent.GetStringExtra("TwitterId");The call to GetStringExtra() returns the value passed on the key.