Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Previously working adapter methods crashing app

$
0
0

I am working on a Xamarin.Forms app. I uses the Monkey.Robotics plugin. I have based my app on this sample. It has been previously working. However, having moved the code in full into another project, the last two methods (triggered by the adapter), are causing the app the crash. Only when both are commented out, does the app run. I don't see why this would be, as they are unchanged from the sample where they worked?

namespace Gas_Sense
{
    public partial class HomePage : ContentPage
    {
        IAdapter adapter;
        ObservableCollection<IDevice> devices;

        public HomePage(IAdapter adapter)
        {   
            InitializeComponent();
            this.adapter = adapter;
            this.devices = new ObservableCollection<IDevice>();

            NewDeviceButton.Clicked += async (sender, e) => {

                adapter.StartScanningForDevices (0x180D.UuidFromPartial ()); 

                await Task.Delay (5000); // wait 5 seconds for the scan to complete
                adapter.StopScanningForDevices();

                //user selects the device which goes into var strip as IDevice
                    adapter.ConnectToDevice (strip); 
                }
            };

            adapter.DeviceDiscovered += (object sender, DeviceDiscoveredEventArgs e) => {
                Device.BeginInvokeOnMainThread(() => {
                    devices.Add (e.Device);
                });
            };

            adapter.ScanTimeoutElapsed += (sender, e) => {
                adapter.StopScanningForDevices(); // not sure why it doesn't stop already, if the timeout elapses... or is this a fake timeout we made?
                Device.BeginInvokeOnMainThread ( () => {
                    IsBusy = false;
                    DisplayAlert("Timeout", "Bluetooth scan timeout elapsed, no Devices were found", "OK");
                });
            };
        }
    }
};

Any ideas would be very welcome, as this one has me quite stumped...


Viewing all articles
Browse latest Browse all 91519

Trending Articles