wcoder / Xamarin.Plugin.DeviceOrientation

Cross-platform plugin to work with screen orientation of mobile device.
MIT License
61 stars 19 forks source link

Android: Cannot access a disposed object. #23

Open jtillyt opened 4 years ago

jtillyt commented 4 years ago

DeviceOrientationImplementation.set_IsListenerEnabled (System.Boolean value) System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Plugin.DeviceOrientation.OrientationListener'.

This is thrown when the following override in the MainActivity is called after switching away from app and then back to app: public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig) { DeviceOrientationImplementation.NotifyOrientationChange(newConfig.Orientation); }

Repo steps: Tested on Android v8 and v9

AlfonChitoSalano commented 3 years ago

I am also experiencing this one here is our logs

Call Stack DeviceOrientationImplementation CurrentOrientation

Exception Message System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.App.Activity'.

I think this caused when the lifecycle listener is disposed here line 24 https://github.com/jamesmontemagno/CurrentActivityPlugin/blob/f8f6e1c046087fe23117483a6f826bfe7ac627dc/src/Plugin.CurrentActivity.Android/CurrentActivity/CurrentActivityImplementation.cs. Would it be possible if the fix could have null checker here then, send the previously saved orientation back here line 55 https://github.com/wcoder/Xamarin.Plugin.DeviceOrientation/blob/12116720c8c6ee1cbf69b785a96a1253d664d0fc/src/DeviceOrientation/Plugin.DeviceOrientation.Android/DeviceOrientationImplementation.cs?

thisisthekap commented 3 years ago

@wcoder Do you think adding the null checks in DeviceOrientationImplementation could fix this issue?

If so: Might we introduce other side effects with this change? (e.g. broken state handling)

thisisthekap commented 3 years ago

@wcoder @jaytilly What do you think about the null check solution?