1
votes

i'm new in developing android in xamarin i just want to ask in how to pass data through other activity using intent ? This thing work (https://developer.xamarin.com/recipes/android/fundamentals/activity/pass_data_between_activity/) but i want to collect first all the data in 2 activity before they show the summary in my 3rd activity.(by the way i'm creating a registration app thanks for the future answers :) )

2
You need to pass the information from your first to the second activity and than to the third one. If you don't want to do that you have to persist them some where. - tequila slammer

2 Answers

3
votes
  1. On the first activity you create the second activity by an intent and use the method PutExtra to pass the data you want with a relevant key name that you will need after starting the new activity to retrieve the data.

    var secondActivity = new Intent (this, typeof(SecondActivity));
    
    secondActivity.PutExtra ("Data", "Sample Data");
    
    StartActivity(secondActivity);
    
  2. On second activity OnCreate retrieve the data using the key name it was stored with and the correct method relevant to the data type passed. In this example as is a string by calling Intent.GetStringExtra.

    string text = Intent.GetStringExtra ("Data") ?? "Data not available";
    
  3. You can repeat 1 & 2 for the summary activity.

0
votes

you can pass whole object and desterilize that in another activity like this

//To pass:
intent.putExtra("yourKey", item);

// To retrieve object in second Activity
getIntent().getSerializableExtra("yourKey");

For only single value you can use

//Method 1
string code = Intent.GetStringExtra("id") ?? string.Empty;
string name = Intent.GetStringExtra("Name") ?? string.Empty;

//OR

//Method 2

string Id = Intent.GetStringExtra("id") ?? string.Empty;
Item item = new Item();
item = itemRepo.Find(Convert.ToInt32(id));