Reputation: 75
I have an Android fragment that has a function that outputs a hexadecimal string. I need some way of either opening this fragment from Xamarin Forms code, or sending the string to my Xamarin Forms page.
I have tried to implement a MessagingCenter script that would send the string to my Xamarin Forms code, but my issue is that I cannot figure out how to create an intent from Forms that would start the Android Fragment. What I need is for some way that when a button is pressed in forms, it would either call the Fragment or open an android page with the fragment.
Xamarin Forms:
private void OnGenerate(object sender, EventArgs e)
{
MessagingCenter.Subscribe<App, string>(App.Current, "OpenPage", (snd, arg) =>
{
Device.BeginInvokeOnMainThread(() => {
tagLabel.Text = arg;
});
});
}
Upvotes: 1
Views: 273
Reputation: 5099
Why dont you just use the Preferences API? You just add the nuget package to your Core and Android projects.
Then in your Android project, you store the value
Preferences.Set("my_key", "my_value");
and in your Core project, you can just get that value using
var myValue = Preferences.Get("my_key", "default_value");
Upvotes: 1