Xamarin Forms Android

Ilim Gusseinov 81 Reputation points
2022-05-15T05:55:18.877+00:00

Hello. Please tell me how to turn from the class of folders in the Android namespace to the general classes of the project. I tried to output data through interfaces, but it did not give results, I also accessed the project classes through an instance of the class, but this also does not give results. How to solve this problem of data output from the Android space class to the general classes of the project? and if possible, please post the code of your solution . Thanks !

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,656 Reputation points Microsoft Vendor
    2022-05-16T07:30:08.877+00:00

    Hello,​

    How to solve this problem of data output from the Android space class to the general classes of the project?

    Do you want to transfer data from Xamarin.Android project to Share project?

    If so, you can use MessageCenter to achieve it. Send a message from the Xamarin.Android project which will then be received by the Share project.

    ===========
    Update=============

    If you want to transfer data from DataSource.cs to MainPage.xaml.cs

    For example, I transfer result data from Accelerometer_ReadingChanged method of DataSource.cs like following code.

       void Accelerometer_ReadingChanged(object sender, AccelerometerChangedEventArgs e)  
                {  
                    var data = e.Reading;  
                    result = counter / 2;  
       //add transfer code here  
                   MessagingCenter.Send<Object, string>(this, "TestMessage", result.ToString());  
               }  
    

    Then, you can get result in MainPage.xaml.cs , for testing, I set the text for Rakaat_1.Text

       public MainPage()  
               {  
                   InitializeComponent();  
         
                   MessagingCenter.Subscribe<Object, string>(this, "TestMessage", (sender, arg) =>  
                   {  
                       string message = arg;  
                       Rakaat_1.Text = message;  
                   });  
                    
               }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful