Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to pass data from android mainactivity to pcl mainpage

SreeeeSreeee INMember ✭✭✭✭✭

Hi,

In my xamarin forms project. I have a string value at android mainactivity. I need this value in pcl mainpage.

Thanks in advance :)

Best Answer

  • SreeeeSreeee INMember ✭✭✭✭✭
    Accepted Answer

    Solved this issue by pass it via the constructor of the Forms App.
    LoadApplication(new App("mystring"));

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Raise an event?
    Send a MessageCenter message?
    Sent it as a parameter to inject when you instantiate an object?
    Reference it in a DependencyServer?

    There's lots of ways - you'll just have to decide what works for your need and architecture.

  • SreeeeSreeee INMember ✭✭✭✭✭
    Accepted Answer

    Solved this issue by pass it via the constructor of the Forms App.
    LoadApplication(new App("mystring"));

  • AlbertoJrAlbertoJr Member

    Hello Sreee,
    Can you show me, how you get the "mystring" into your PCL?

  • SreeeeSreeee INMember ✭✭✭✭✭

    @AlbertoJr said:
    Hello Sreee,
    Can you show me, how you get the "mystring" into your PCL?

    Late reply because of the holidays :)

    Mainacivity.cs

        //My string value
        var value= "sreejith";
        //Add value as an argument when calling pcl App
        LoadApplication(new App(value));
    

    App.xaml.cs in pcl

        //Add value as the argument in App
        public App(string value)
                {
                    InitializeComponent();
                    MainPage = new Myapp.MainPage(value);//passing the value to mainpage
                }
    
  • AlbertoJrAlbertoJr Member

    Thank You! Sreee, I going to check it, I did already with the DependencyService...

  • JoannaGJoannaG Member ✭✭✭

    @AlbertoJr,

    Can you please share codes in renderer and pcl using dependency service.

Sign In or Register to comment.