Passing values between Activities using MonoDroid
Posted
by Wallym
on ASP.net Weblogs
See other posts from ASP.net Weblogs
or by Wallym
Published on Tue, 08 Feb 2011 15:00:00 GMT
Indexed on
2011/02/08
15:26 UTC
Read the original article
Hit count: 454
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.
© ASP.net Weblogs or respective owner