user8120868
user8120868

Reputation:

Null GetStringExtra (Intent) - Xamarin.Droid

I am passing data from one activity1 to activity2 using intents. I consoled my data in activity1 and i am able to see the data that i am sending to activity2. But when i console the data i am receiving in activity2, i don't receiving any data. I have basically followed the right procedure in using intents but the trick isn't working.

Question: Does async process affect the using of intents?

activity1

private async Task GetData()
{
    var firebase = new FirebaseClient(FirebaseUrl);
    var items = await firebase.Child("TableName").OnceAsync<Person>();

    foreach (var item in items)
    {
        Person details = new Person();
        details.Name = item.Object.Name;
        person.Add(details);
    }

    void OnItemClick(object sender, int position)
    {
        Intent peaceHeroDetail = new Intent(this, typeof(PersonDetailActivity));
        Intent.PutExtra(PersonDetailActivity.EXTRA_NAME, person[position].Name.ToString());
        // the value of what is being sent is seen
        Console.WriteLine("This is selected person " +person[position].Name);
    }
}

activity2

public const string EXTRA_NAME = "Person Name";
string PName = Intent.GetStringExtra(EXTRA_NAME);
//it is empty
Console.WriteLine("This is the received detail "+ PName);

Upvotes: 0

Views: 802

Answers (1)

Paul Karam
Paul Karam

Reputation: 4210

Since your comment showed that it was a mistake, I deleted old answer and gave you this update.

UPDATE:

Check this following article: Pass data between activities

In your first activity, you should change this:

Intent peaceHeroDetail = new Intent(this, typeof(PersonDetailActivity));
Intent.PutExtra(PersonDetailActivity.EXTRA_NAME, person[position].Name.ToString());

to this:

Intent peaceHeroDetail = new Intent(this, typeof(PersonDetailActivity));
peaceHeroDetail.PutExtra(PersonDetailActivity.EXTRA_NAME, person[position].Name.ToString());

and then use : StartActivity(peaceHeroDetail);

Upvotes: 1

Related Questions