2

I have a list that gets its data from a form (where you can fill in the name and the amount), now when i want to send only one variable it works.

I want to do the following:

//Activity 1
    var second = new Intent(this, typeof(Activity2)); 
    second.PutExtra("name", name);
    second.PutExtra("amount", amount);
    StartActivity(second);

//Activity 2
    string name = Intent.GetStringExtra("name") ?? "No Data";
    string amount= Intent.GetStringExtra("amount") ?? "No Data";

but when i get the data on the other activity, amount and name have the same value

BaanAxe
  • 317
  • 2
  • 15

1 Answers1

1

If your items are from the same object/class..
You can create a class that has all these properties and then use Json do serialize/deserialize between your activities for example:

 //Activity 1
 var objectString = Newtonsoft.Json.JsonConvert.SerializeObject(yourClass);
 var activity = new Intent(this, typeof(activityName));
 activity.PutExtra("yourObjectName", objectString );
 StartActivity(activity);

//Activity 2                
var _objectstring = Intent.GetStringExtra("yourObjectName") ?? string.Empty;            
if (!string.IsNullOrEmpty(_objectstring))
{
    var instanceOfYouClass = JsonConvert.DeserializeObject<yourClass>(_objectstring);
}
Milen
  • 8,697
  • 7
  • 43
  • 57
  • 2
    Why would you suggest that when what he does is completely legitimate and he obviously has some other issue. Packing primitive data types into an object and then serializing/deserializing them seems too extreme. – Alex.F Nov 10 '14 at 12:54