Alberto López Alberto López -5 years ago 90
SQL Question

How can I pass a variable between 2 activities?

I am using mysql to retrieve a code into my Main Activity, which stores as a string. This works, but when I try to pass it to another activity, it just wont work. I may be wrong, but I'm passing it as I would do with a regular c# variable.

Whats the correct way to pass variables (string, int) from one activity to another?

Answer Source

You do it this way, while passing:

var intent = new Intent (this, typeof(MyActivity));
intent.PutExtra("MyString", "This is a string");
intent.PutExtra("MyInt", 20);
StartActivity (intent);

while retrieving:

string text = Intent.GetStringExtra ("MyString");
//you get
//This is a string
int number = Intent.GetIntExtra ("MyInt");
//you get
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download