Skip to content

Instantly share code, notes, and snippets.

@matthewrdev
matthewrdev / PeerConnectionHelper.cs
Last active November 15, 2021 23:59
Utility class to detect severed peer connections in Xamarin.Android.
/// <summary>
/// Helper class to detect when .NET objects with a Java peer object have been "severed".
/// <para/>
/// Peer objects are .NET types which implement IJavaObject , e.g. all Java.Lang.Object and Java.Lang.Throwable subclasses.
/// Instances of these types have two "halfs" a managed peer and a native peer.
/// <list type="bullet">
/// <item>The managed peer is an instance of the C# class.</item>
/// <item>The native peer is an instance of a Java class within the Android runtime VM, and the C# IJavaObject.Handle property contains a JNI global reference to the native peer.</item>
/// </list>
/// There are two types of native peers: