[WP7Dev] Double tap when you expect only one
I've been developing a free application to do some PC remote control on Windows Phone 7, and it's been very instructive in many ways.
To improve the quality of the software, and be notified when an unhandled exception occurs somewhere in my code, or in someone else's code executed on my behalf, I've added a small opt-in unhandled exception reporting feature. This basically sends me back information about the device, most of what's available in DeviceExtendedProperties for device aggregation of exceptions, plus some informations like the culture and, of course, the exception stacktrace and details.
The MarketplaceDetailTask exception
A few recurring exceptions have popped up a lot recently, and one coming often is the following :
Exception : System.InvalidOperationException: Navigation is not allowed when the task is not in the foreground. Error: -2147220989
at Microsoft.Phone.Shell.Interop.ShellPageManagerNativeMethods.CheckHResult(Int32 hr)
at Microsoft.Phone.Shell.Interop.ShellPageManager.NavigateToExternalPage(String pageUri, Byte[] args)
at Microsoft.Phone.Tasks.ChooserHelper.Navigate(Uri appUri, ParameterPropertyBag ppb)
at Microsoft.Phone.Tasks.MarketplaceLauncher.Show(MarketplaceContent content, MarketplaceOperation operation, String context)
at Microsoft.Phone.Tasks.MarketplaceDetailTask.Show()
This code is called when a user clicks on the purchase image located on some page of the software, and it looks like this :
[code:c#]
void PurchaseImage_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
var details = new MarketplaceDetailTask();
details.ContentIdentifier = "d0736804-b0f6-df11-9264-00237de2db9e";
details.Show();
}
[/code]
The call is performed directly on the image's ManipulationCompleted event.
I've been trying to reproduce it for a few times and I finally got it: The user is tapping more than once on the image.
I can see a few reasons why:
- The ManipulationCompleted event is fairly sensitive and is raised multiple times when the user did not tap twice
- The user did actually tap twice because the action did not answer fast enough.
- The user tapped twice because he is used to always tap twice, as some PC users do... (You know, double clicking on hyperlinks in browsers, things like that)
What do we do about it ?
There may be actually more, be this actually tells me a lot.
First, I should be having some kind of visual feedback on the click of that image, to tell the user that he has done something (and also to actually follow the design guidelines)
Second, that even if the feedback is there, that there may always be two subsequent clicks, and one that may be executed after the first has called the MarketplaceDetailTask.Show(), and the application has been deactivated. I cannot do much about it, except handle the exception silently or track the actual application state and not call the method.
I'll go with the exception handler for now as it is not a very critical peace of code, but I'd rather have some way of that tell me that the application cannot do that reliably and not have to handle an exception. The API is rather limited on that side, where the PhoneApplicationService is only raising events and does not expose the current "activation" state.
Any other examples of exceptions ?
I'll talk more about some other findings this opt-in exception reporting feature has brought me, with some that seem to be pretty tricky.