I have a custom view renderer for android that works with a SurfaceView.
When directly poping to root from the page that uses the custom renderer, the dispose or surface destroyed methods get called.
As soon as i add another page in the stack on top of the page-using-custom-viewrenderer, and PopToRoot from there, the dispose/surface destroyed methods do NOT get called.
Summarized: The SurfaceDestroyed method does not get called as soon as another page is placed on top of it, which makes it impossible to release the camera.
Is this intended? Or a bug? How could i work around that? Right now its not possible to properly releasing the android camera.
Using: Xamarin.Forms 1.3.5-pre1 and Xamarin.Android.Support.v4 21.0.3.0
Here is some dumbed down sample code which enables to check, via console, if the methods are called.
[assembly: ExportRenderer(typeof(ScannerView), typeof(RebuyApp.Android.Renderers.ScannerViewRenderer))]
namespace RebuyApp.Android.Renderers
{
public class ScannerViewRenderer : ViewRenderer<ScannerView, SurfaceView>, ISurfaceHolderCallback, Camera.IPreviewCallback
{
public void SurfaceDestroyed(ISurfaceHolder holder)
{
Log.Debug("ScannerViewRenderer", "SurfaceDestroyed");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
Log.Debug("ScannerViewRenderer", "Dispose");
}
base.Dispose(disposing);
}
public void SurfaceChanged(ISurfaceHolder holder, global::Android.Graphics.Format format, int width, int height)
{
Log.Debug("ScannerViewRenderer", "SurfaceChanged");
}
public void SurfaceCreated(ISurfaceHolder holder)
{
Log.Debug("ScannerViewRenderer", "SurfaceCreated");
}
public void OnPreviewFrame(byte[] bytes, Camera camera)
{
Log.Debug("ScannerViewRenderer", "Dispose");
}
protected override void OnElementChanged(ElementChangedEventArgs<ScannerView> e)
{
Log.Debug("ScannerViewRenderer", "OnElementChanged");
base.OnElementChanged(e);
if (Control == null) {
Log.Debug("ScannerViewRenderer", "Control == null");
var surfaceView = new SurfaceView(Context);
surfaceView.Holder.AddCallback(this);
SetNativeControl(surfaceView);
}
}
}
}