this is my situation.
I have an app written in Xamarin that supports both Droid and iOS. Each of these projects require platform independent Bluetooth API. So, what I've done is create an interface that I use with a DependencyService. The field I need is a list of Bluetooth Devices... this is simple enough if I'm developing for one platform. But in this case, my Bluetooth implementation "detects" devices on it own thread, so it's not necessarily possible for me to return a String[] Names.. My solution was this, I create a class and within the class have a String[] and since the class is a "reference" I assumed as I add to the list later in the code the changes would reflect in my DependencyService... but sadly, no, this is not the case..... Here's some code for the situation.
This is the definition of my class that I 'harbor' my array of items in.
namespace ThoughtCastRewrite.BluetoothX
{
public class BluetoothItems
{
public string[] ListBTItems = new string[10];
public BluetoothItems()
{
ListBTItems[2] = "TEST";
ListBTItems[6] = "WtF?";
}
public void Set(string stringToAdd)
{
ListBTItems[4] = stringToAdd;
}
}
}
This bit of code is in the Cross-Platform project
BluetoothItems bluetoothItemList = DependencyService.Get<ISlateBluetoothItems>().IBluetoothTest;
listView.ItemsSource = bluetoothItemList.ListBTItems;
Now here is the Droid code:
BluetoothItems bluetoothItems = new BluetoothItems();
public BluetoothItems IBluetoothTest { get => bluetoothItems; }
Ok, so, this may seem obvious, but TEST and WtF? are added to my listview.
But, in my MainActivity (Droid portion again) after the entire view loads I call
bluetoothItems.Set("TEST");
and the "TEST" item is never added to my list!
Am I being clear here about what I'm trying to do?
Any assistance is welcomed.