Bug 59919 - Multiple rapid taps on the picker crashes the app (Android)
Summary: Multiple rapid taps on the picker crashes the app (Android)
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.4.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-10-03 14:07 UTC by Mihail Duchev
Modified: 2017-11-15 18:59 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

The output for when the bug occurs (4.40 KB, text/plain)
2017-10-03 14:07 UTC, Mihail Duchev

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Mihail Duchev 2017-10-03 14:07:07 UTC
Created attachment 25073 [details]
The output for when the bug occurs

I have found an issue where if you have a picker within an Android app, that has AppCompat enabled and has custom renderer inheriting from Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer, when you tap the picker very rapidly multiple times and after each tap you tap outside the picker (in order to close it), the app crashes after several clicks to open-close the picker. 
The steps are very fast, but are as follows: click on the picker in order to open it, after that very fast click outside the picker. Repeat multiple times.

This is a possible duplicate/regression of #41717.

I have attached the output, which tells me that there is a null reference exception causing the app to crashes. The cause of this is in line 115 from PickerRenderer for AppCompat. 
Here is the line: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs#L115

I guess that at some point before closing/opening the next picker, the dialog becomes null, even after all of the checks.

When we look at the git blame, we can see this:
This was the fix for 41717 that was released with 2.4.

Unfortunately, I can't confirm that this was an issue before the 2.4 release. 

A sample of my picker renderer:

using Android.Util;
using MyProject.CustomRenderers;
using MyProject.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using PickerRenderer = Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer;

[assembly: ExportRenderer(typeof(MyPicker), typeof(MyPickerRenderer))]
namespace MyProject.Droid.Renderers
    public class MyPickerRenderer : PickerRenderer
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)

            if (e.OldElement == null && Element is MyPicker pickerElement)
                // Change fontSize and placeholderFontSize
                if (pickerElement.FontSize.HasValue)
                    Control.SetTextSize(ComplexUnitType.Sp, (float)pickerElement.FontSize.Value);
Comment 1 Paul DiPietro [MSFT] 2017-10-03 16:52:57 UTC
What sort of device are you testing this on (for speed, I assume you're using a device) and do you have a more complete project to upload for debugging? I cannot seem to reproduce this despite rather quickly tapping in and out of the Picker on an S8 device.
Comment 2 Mihail Duchev 2017-10-04 09:32:40 UTC
Sorry for missing this - this happened on my HTC 10 running Android 7.0 and also on Samsung Galaxy S6 Edge running 7.0.
Unfortunately, I cannot upload a sample project, but I will try my best to describe the workflow that we have:

1) We are opening a certain page;
2) In the ctor we create an instance of our binded viewModel;
3) In the viewModel's ctor we start loading the data to the picker. The data is being loaded asynchronously via GET request. The request is not being awaited;
4) The picker is being binded to an ObservableCollection of other viewModels. When we get the result from our request, we simply set the result to the collection.

That's it.

NOTE: Opening the picker doesn't initiate another GET request.
Comment 3 Paul DiPietro [MSFT] 2017-11-15 18:59:14 UTC
To the reporter or anyone else experiencing the issue, reopen this when we can get a reproduction project to help us investigate further. Thanks.