Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Cannot access a disposed object. #23

Open
jtillyt opened this issue Dec 26, 2019 · 3 comments
Open

Android: Cannot access a disposed object. #23

jtillyt opened this issue Dec 26, 2019 · 3 comments
Labels

Comments

@jtillyt
Copy link

jtillyt commented Dec 26, 2019

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

  • Implement override so that NotifyOrientationChange is called in Android
  • Open app and use so the LockOrientation is called
  • Put app in background
  • Put app back in foreground
  • When changing the orientation, the app will crash because the OrientationListener is disposed.
@wcoder wcoder added the Android label Jun 23, 2020
@AlfonChitoSalano
Copy link

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
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants