5,380 questions
I got it.
The error was in line 32 of the MainActivity.cs file.
It should be:
StartActivity(typeof(myIntent)); //earlier it was wrongly doing this for details_page
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I am trying to pass the text of an EditText object from one screen (MainActivity.cs) in Xamarin Forms as the Text of another EditText in a second screen (details_page.cs).
However, on the second screen when I am trying to get the value of Intent.GetExtraString() it is always coming up as null.
Any idea what may be wrong here:
MainActivity.cs
using System;
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using Android.Widget;
using Android.Content;
namespace hikmatNotes
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
EditText inputNotes;
Button btnProcess;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
inputNotes = FindViewById<EditText>(Resource.Id.inputNotes);
btnProcess = FindViewById<Button>(Resource.Id.btnProcess);
// btnProcess.Click += btnProcess_click;
btnProcess.Click += delegate
{
var myIntent = new Intent(this, typeof(details_page));
myIntent.PutExtra("InputNotes", inputNotes.Text.ToString());
StartActivity(typeof(details_page));
};
details_page.cs
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace hikmatNotes
{
[Activity(Label = "Activity1")]
public class details_page : Activity
{
EditText outputNotes;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.details_page);
outputNotes = FindViewById<EditText>(Resource.Id.outputtNotes);
string inputText = Intent.GetStringExtra("InputNotes");
outputNotes.Text = inputText;
}
}
}
I got it.
The error was in line 32 of the MainActivity.cs file.
It should be:
StartActivity(typeof(myIntent)); //earlier it was wrongly doing this for details_page