<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Windows Phone COE</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/wpukcoe/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/wpukcoe/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:27:19 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>How to test an app on a Windows Phone device with 256MB of memory</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/how-to-test-an-app-on-a-windows-phone-device-with-256mb-of-memory</link>
      <pubDate>Mon, 02 Apr 2012 08:53:51 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/04/02/how-to-test-an-app-on-a-windows-phone-device-with-256mb-of-memory/</guid>
      <description><![CDATA[On 27th Feb 2012 Microsoft has announced support for lower cost devices, such as Nokia Lumia 610....]]></description>
      <content:encoded><![CDATA[<p>On 27th Feb 2012 Microsoft has announced support for lower cost devices, such as <a href="https://europe.nokia.com/find-products/devices/nokia-lumia-610">Nokia Lumia 610</a>. This is a great opportunity to expand Windows Phone’s customer segments. T<span style="line-height: 115%; font-family: &quot;Verdana&quot;, &quot;sans-serif&quot;; color: #4c4c4c; font-size: 8pt; mso-fareast-font-family: &#39;Times New Roman&#39;; mso-bidi-font-family: &#39;Times New Roman&#39;; mso-ansi-language: en-us; mso-fareast-language: zh-cn; mso-bidi-language: ar-sa">his comes with an updated Windows Phone OS and release of <a href="https://go.microsoft.com/fwlink/?LinkID=244021">SDK 7.1.1</a>.</span></p>  <p>The update to the Windows Phone OS (build 8773) is a minor update to improve user experience on devices with 256MB of memory. Windows Phone has always supported devices with 256MB, but this update is about having the experience “buttery smooth”. This means the update is primarily about supporting lower cost devices.</p>  <p>Most applications will run seamlessly on lower cost devices and to verify your application on these devices please refer to the test case below. The test case starts with brief description of the changes in the Windows Phone Platform on 256MB devices and follows up with the test scenarios to verify. </p>  <p>&#160;</p>  <table border="1" cellspacing="0" cellpadding="12"><tbody>     <tr>       <td valign="top" width="798">         <p><strong>TEST CASE PURPOSE</strong></p>          <p>An OS update to the existing Windows Phone 7.5 improves support for devices with 256 MB of memory. This testcase verifies that the application will function correctly on lower cost devices with 256MB memory.            <br />In general old applications should work since Marketplace guidelines required all apps not to use more than 90MB of memory on devices with 256MB of memory and handle disabled background agents correctly.</p>          <p>Key notes:            <br />-If app exceeds memory allowance, the app will be terminated by OS.</p>          <p>-There is no generic background agent (<a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.scheduler.periodictask(v=VS.92).aspx">PeriodicTask</a> and <a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.scheduler.resourceintensivetask(v=vs.92).aspx">ResourceIntensiveTask</a>) functionality on lower cost devices with 256MB. App may terminate with unhandled exception if not accounting for disabled background agents. </p>          <p>-Note that background audio is supported.</p>          <p>-Verify app performance. If application is memory intensive, then with memory paging the app performance can decrease. Verify background audio and general app responsiveness.</p>          <p>-Verify playback of high resolution videos. Maximum 800 x 480 video resolution is supported. Max supported bitrate is up to 4Mbps regardless of codec (*). Use <a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.info.mediacapabilities.ismultiresolutionvideosupported(v=vs.92).aspx">IsMultiResolutionVideoSupported</a> API to detect device capabilities.</p>          <p>&#160;</p>          <p><strong>TEST STEPS: </strong></p>          <p>Install the application on device with 256 MB of memory and test following areas: (** for testing in emulator see end of the testcase)</p>          <p>1. Execute scenarios which are memory intensive. VERIFY: App is not killed by OS when the user is using a memory intensive feature.</p>          <p>2. Execute scenarios that would exercise the background agent code (if applicable). There are no crashes or misleading error messages because generic background agents are not available on lower cost devices.</p>          <p>3. Pin secondary tile to start. Some apps use background agents to update the tile. Application must not crash or give confusing error message to the user. </p>          <p>4. Background audio does not stutter.</p>          <p>5. Verify performance and app responsiveness to user’s interactions.</p>          <p>6. App’s launch time meets Marketplace requirements – (<a href="https://msdn.microsoft.com/en-us/library/hh184840(v=vs.92).aspx">5.2.1 Launch Time</a>)</p>          <p>7. Test video playback if applicable. Focus on high resolution videos. VERIFY: All videos play or a user friendly error message is displayed for videos that do not play. You may see generic phone error “Sorry, we can’t play this file on your phone”.</p>          <p>&#160;</p>          <p>(**) Alternative way of testing this is using Windows Phone Emulator with 256MB of memory. Download the SDK update at <a href="https://go.microsoft.com/fwlink/?LinkID=244021">https://go.microsoft.com/fwlink/?LinkID=244021</a></p>          <p>Keep in mind that performance on emulator does not reflect actual speed of the phone device, as the desktop PC is more powerful. </p>          <p>(*) See ‘Supported Media Codecs for Windows Phone’ with regard to 7x27a processor used in 256MB devices: <a href="https://msdn.microsoft.com/en-us/library/ff462087(v=vs.92).aspx">https://msdn.microsoft.com/en-us/library/ff462087(v=vs.92).aspx</a></p>          <p>&#160;</p>          <p>Memory and performance issues can be investigated using free Performance Profiler which is part of the Windows Phone SDK. Overview of the profiler at <a href="https://msdn.microsoft.com/en-us/library/hh202934(v=vs.92).aspx">https://msdn.microsoft.com/en-us/library/hh202934(v=vs.92).aspx</a></p>          <p>Background Agent Best Practices for Windows Phone: <a href="https://msdn.microsoft.com/en-us/library/hh202944(v=vs.92).aspx">https://msdn.microsoft.com/en-us/library/hh202944(v=vs.92).aspx</a></p>       </td>     </tr>   </tbody></table>  <p>&#160;</p>  <h1>&#160;</h1>  <h3>Marketplace FAQ:</h3>  <p>Q: My application is already in Marketplace, will the application be visible in Marketplace on lower cost devices?</p>  <p>A: Yes, however some applications which exceed the allowed memory limit will be opted out by default from Marketplace on lower cost devices to avoid user’s dissatisfaction. </p>  <p>Q: How are failing apps determined?</p>  <p>A: Opt-out is based on anonymous memory usage statistics, which are received from users that take part in a feedback program (<a href="https://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/02/27/get-ready-for-60-more-potential-customers.aspx">source</a>, section Windows Phone SDK Update &amp; Preview)</p>  <p>Q: My app is opted out from Marketplace on lower cost devices. How do I opt the app in?</p>  <p>A: Submit an updated app to App Hub, the app will be re-tested on lower cost devices. Once the application passes certification, the application will become available.</p>  <p>Q: My application will not be able to work on lower cost devices how do I opt out?</p>  <p>A: Add requirement <a href="https://msdn.microsoft.com/en-us/library/hh855081(v=vs.92).aspx">ID_REQ_MEMORY_90</a> to the WMAppManifest.xml file.</p>  <p>&#160;</p>  <p>&#160;</p>  <h3>Resources:</h3>  <p><a href="https://msdn.microsoft.com/en-us/library/hh855081(v=vs.92).aspx#featureConsiderations">Developing for 256-MB Devices</a>     <br /><a href="https://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/03/07/optimizing-apps-for-lower-cost-devices.aspx">Optimizing Apps for Lower Cost Devices</a>     <br /><a href="https://www.developer.nokia.com/Community/Wiki/Best_practice_tips_for_delivering_apps_to_Windows_Phone_with_256_MB">Best Practice Tips for Delivering Apps to 256 MB Devices</a>     <br /><a href="https://windowsteamblog.com/windows_phone/b/wpdev/archive/2012/02/27/get-ready-for-60-more-potential-customers.aspx">Get Ready for 60% More Potential Customers</a>     <br /><a href="https://windowsteamblog.com/windows_phone/b/windowsphone/archive/2012/02/27/windows-phone-at-mobile-world-congress-2012.aspx">Windows Phone at Mobile World Congress 2012</a>     <br /><a href="https://channel9.msdn.com/Shows/Inside+Windows+Phone/Inside-Windows-Phone-33--Windows-Phone-75-Refresh--60-more-Opportunity">Video: Inside Windows Phone #33 | Windows Phone 7.5 Refresh &amp; 60% more Opportunity!</a>     <br /><a href="https://go.microsoft.com/fwlink/?LinkID=244021">Tools: Windows Phone SDK 7.1.1 Update</a></p>  <p>&#160;</p>  <p><em>Written by</em>&#160;<a href="https://blogs.msdn.com/wpukcoe/archive/tags/Petr+Sedlacek/default.aspx"><u><font color="#000080">Petr Sedlacek</font></u></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Back Button</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/back-button</link>
      <pubDate>Fri, 09 Mar 2012 04:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/03/09/back-button/</guid>
      <description><![CDATA[&nbsp;
Marketplace has specific requirements (5.2.4) for use of hardware back button, which can be...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>Marketplace has specific requirements (5.2.4) for use of hardware back button, which can be referenced <a href="https://msdn.microsoft.com/en-us/library/hh184840(v=vs.92).aspx">here</a>, however there are few scenarios where it is easy to overlook these requirements. This article describes some common issues related to back button which we have come across while testing showcase apps for Windows Phone.</p>
<h3>Back Button and Secondary Tiles</h3>
<p>When user presses the back button after launching the application from secondary tile, the application should exit and should not navigate to the home page/panorama. The main principle for deep linking is to be able to easily access a particular piece of content as opposed to be an alternative method of entering the application. The user has the option to pin the application to the start if they choose - this provides the primary entry point to the application. If the user pins a secondary tile, this is a deliberate action to pin the piece of content and is clearly distinct from pinning the application.</p>
<p>For example: Open the People hub and scroll through a list of contacts then select a contact and open the context menu to 'pin to start menu'.</p>
<ul>
<li>You can now use the contact as a separate entity on the main start menu.</li>
<li>If you click on the contact you can edit it or use the contact card to call/email/etc.</li>
<li>Clicking back on the contact brings you back to the start menu and not into the People Hub.</li>
</ul>
<p>Similarly, if you pin a game to the start menu, it's because you want to have quick access to the game.</p>
<ul>
<li>The user doesn&rsquo;t expect to be taken to the Games hub when he/she backs out of the game, as they were never there.</li>
</ul>
<p>This is because the user expects 'back' to take them back to the previous place (back means back).</p>
<p>It is more confusing if 'back' takes you to a page you have not been on i.e. the panorama or home page of the app.</p>
<p>It is important that quality applications follow the same model as the main hub on the device which the user is already familiar with.</p>
<h3>Back Button and Search Extensibility</h3>
<p>In Mango, applications can use App Connect to extend the Search experience on Windows Phone. With App Connect, users who search the web with the Search button can launch a relevant page in your application from Bing search results. If your app makes use of this feature then you should ensure that when user presses the back button after launching the app from the search results then then he/she should be returned back to the search results and not to the home panorama of the application. For more details on Search Extensibility refer <a href="https://msdn.microsoft.com/en-us/library/hh202957(v=vs.92).aspx">here</a></p>
<h3>Back Button and Very Deep Page Navigation</h3>
<p>Very deep page navigations will make it difficult for the user to get back to the main page without restarting the app. For example consider apps which have search option in each page. When user makes a search, it opens a new page with results and provides option for another search. When the search action is performed repeatedly it leads to multiple pages in back stack resulting in a very deep navigation. To prevent such a navigation loop, the application should not provide the search option in the search results page. User must press hardware back button and modify his/her search criteria to initiate a new search.</p>
<h3>Back Button and Games</h3>
<p>When the Back button is pressed during gameplay, the game can do one of the following</p>
<ul>
<li>The game can choose to present a dialog which provides user the option to pause or exit the game. Pressing the back button again should dismiss this dialog.</li>
<li>Navigate the user to the prior menu screen. Pressing the back button again should continue to return the user to the previous menu or page.</li>
</ul>
<p><b>Outside of gameplay</b>, such as within the game's menu system, pressing back button must return to the previous menu or page.</p>
<p><b>At the game&rsquo;s initial (start) screen</b>, pressing back button must exit the game.</p>
<h3>Back Button and Dialog Boxes</h3>
<p>If the current page displays a dialog or context menu, then pressing the Back button must close the menu or dialog and return the user to the screen where the context menu or dialog box was opened. For example refer back button behaviour for the context menu and dialog which pop up on application list page of the native device.</p>
<ul>
<li>Tap and hold on any application listed on application page of the phone. A context menu, as in screenshot below, is shown. Press the hardware back button and the context menu gets dismissed.</li>
<li>Tap and hold on any application listed on application page of the phone. Select &ldquo;uninstall&rdquo; from the context menu. A dialog box, as show in screenshot below, is shown. Press the hardware back button and the dialog box gets dismissed.</li>
</ul>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/2451.ContextMenu_347887C1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/2451.ContextMenu_5F00_347887C1.png"><img style="border: 0px currentcolor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="ContextMenu" border="0" alt="ContextMenu" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/5187.ContextMenu_thumb_3DF14637.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/5187.ContextMenu_5F00_thumb_5F00_3DF14637.png" width="148" height="244" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3757.DialogBox_3A1C4FBB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3757.DialogBox_5F00_3A1C4FBB.png"><img style="display: inline; background-image: none;" title="DialogBox" border="0" alt="DialogBox" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0118.DialogBox_thumb_0673E35D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0118.DialogBox_5F00_thumb_5F00_0673E35D.png" width="148" height="244" /></a></p>
<p>If the application does not dismiss dialog box or context menu when user presses hardware back button or if the application navigates the user to some page other than the one from which dialog box or context menu was invoked then it an issue.</p>
<p>For more good content on back button and to know few implementation&nbsp;tips&nbsp;please refer a related post <a href="https://blogs.msdn.com/b/ptorr/archive/2011/10/06/back-means-back-not-forwards-not-sideways-but-back.aspx">here</a></p>
<p><em>Written by <a title="Amit Jain" href="https://blogs.msdn.com/wpukcoe/archive/tags/Amit+Jain/default.aspx">Amit Jain</a></em></p>]]></content:encoded>
    </item>
    <item>
      <title>Improving application stability by managing button states</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/improving-application-stability-by-managing-button-states</link>
      <pubDate>Thu, 01 Mar 2012 21:49:00 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/03/01/improving-application-stability-by-managing-button-states/</guid>
      <description><![CDATA[While testing applications on Windows Phone we have often come across scenarios where application...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClass0DCE2B46FE8545438BED2A47558F4A0D">
<p>While testing applications on Windows Phone we have often come across scenarios where application crashes when user clicks buttons or links in the app in quick succession. These type of crashes generally occur due to two main reasons</p>
<p>1) Controls for user inputs don&rsquo;t get disabled once user taps on them and until a response has been processed. Example while the app is processing user&rsquo;s selection choice from the list, it takes some time to process the request and user changes his mind and clicks on another item, or submit button for app is enabled even while the app is signing the user into the application on the first click of the button by the user, like below.</p>
<pre class="code"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7178.Button_Not_Disabled_0535AE0A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7178.Button_5F00_Not_5F00_Disabled_5F00_0535AE0A.png"><img style="display: inline; background-image: none;" title="Button_Not_Disabled" border="0" alt="Button_Not_Disabled" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/1234.Button_Not_Disabled_thumb_5A99CD2C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/1234.Button_5F00_Not_5F00_Disabled_5F00_thumb_5F00_5A99CD2C.png" width="148" height="244" /></a></pre>
<pre class="code">&nbsp;</pre>
<p>To avoid such crashes, controls that require user action should not be available for the user to interact with again after a user initially interacts with them until a response is posted.</p>
<p>2) Click events are handled when app is being removed from the foreground but before the app completely transitions to deactivated state. This happens when a user interaction causes the app to navigate the user out of the app. An example of this would be when invoking the <a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.emailcomposetask(v=vs.92).aspx">EmailComposeTask</a>, <a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.smscomposetask(v=vs.92).aspx">SmsComposeTask</a> or <a href="https://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.webbrowsertask(v=vs.92).aspx">WebBrowserTask</a>, for instance if the user taps the email link in the below page multiple times in quick succession then the app is likely to crash.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/5428.Email_Link_664F145E.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/5428.Email_5F00_Link_5F00_664F145E.jpg"><img style="display: inline; background-image: none;" title="Email_Link" border="0" alt="Email_Link" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/8171.Email_Link_thumb_3DD0324A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/8171.Email_5F00_Link_5F00_thumb_5F00_3DD0324A.jpg" width="154" height="244" /></a></p>
<p>The crash log in this case would resemble something as below</p>
<p>System.InvalidOperationException: Navigation is not allowed when the task is not in the foreground. Error: -<b>2147220990</b></p>
<p>&nbsp;&nbsp; at Microsoft.Phone.Shell.Interop.ShellPageManagerNativeMethods.CheckHResult(Int32 hr)</p>
<p>&nbsp;&nbsp; at Microsoft.Phone.Shell.Interop.ShellPageManager.NavigateToExternalPage(String pageUri, Byte[] args)</p>
<p>&nbsp;&nbsp; at Microsoft.Phone.Tasks.ChooserHelper.Navigate(Uri appUri, ParameterPropertyBag ppb)</p>
<p>&nbsp;&nbsp; at Microsoft.Phone.Tasks.EmailComposeTask.Show()</p>
<p>&nbsp;&nbsp; at AppName.View.SharePage.mailHyperlinkButton_Click(Object sender, RoutedEventArgs e)</p>
<p>&nbsp;&nbsp; at System.Windows.Controls.Primitives.ButtonBase.OnClick()</p>
<p>&nbsp;&nbsp; at System.Windows.Controls.HyperlinkButton.OnClick()</p>
<p>&nbsp;&nbsp; at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)</p>
<p>&nbsp;&nbsp; at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)</p>
<p>&nbsp;&nbsp; at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)</p>
<p>The happy path is that EmailComposeTask is invoked when user taps the email link, the email dialog opens and the application gets deactivated i.e. sent to the background. However in above case as the email link was tapped multiple times, the second click is being handled after the email dialog is being opened, but before the app moves to deactivated state. Solution is to put a try/catch around the EmailComposeTask and handle the InvalidOperationException.</p>
<p><code>EmailComposeTask <br />emailComposeTask = new EmailComposeTask(); </code> <br /><code>emailComposeTask.To = "test@test.com"; </code> <br /><code>emailComposeTask.Subject = "Feedback for wpdps"; </code> <br /><code>try </code> <br /><code>{ </code> <br /><code>&nbsp; emailComposeTask.Show();</code></p>
<p><code></code><code>} </code></p>
<p><code>catch(InvalidOperationException) </code> <br /><code>{ </code> <br /><code>&nbsp; // can fail if link is pressed twice in quick </code><code>succession - <br />&nbsp; do nothing as the application </code><code>has already navigated away <br /></code><code>}</code></p>
<p>The above solution also holds good for SmsComposeTask and WebBrowserTask.</p>
<p><em>Written by <a title="Amit Jain" href="https://blogs.msdn.com/wpukcoe/archive/tags/Amit+Jain/default.aspx">Amit Jain</a></em></p>
<pre class="code">&nbsp;</pre>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Background audio in Windows Phone 7.5 (Part 3)</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/background-audio-in-windows-phone-7-5-part-3</link>
      <pubDate>Sat, 11 Feb 2012 04:00:00 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/02/11/background-audio-in-windows-phone-7-5-part-3/</guid>
      <description><![CDATA[The story so far
In the first part of this series on Background Audio the Background Audio feature...]]></description>
      <content:encoded><![CDATA[<h1 class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">The story so far</h1>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">In the <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/09/background-audio-in-windows-phone-7-5-part-1.aspx">first part</a> of this series on Background Audio the Background Audio feature was introduced.</p>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">In the <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/10/background-audio-in-windows-phone-7-5-part-2.aspx">second part</a> of the series various ways to pass information between the application and the audio agent were outlined, including how to specify a playlist from the main application that the agent will play.</p>
<h1 class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">Where we are now</h1>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">In this third part of the series we will focus on the challenges when using Background Audio when streaming from a remote server.</p>
<h1 class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">Challenges with streaming audio</h1>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">As discussed in the last blog post, the events that are raised in the app code are not complete and as full as the events raised in agent code. Taking the example of a track coming to an end, the app code only sees the &ldquo;Unknown&rdquo; and &ldquo;Playing&rdquo; events in its &ldquo;App Side BackgroundAudioPlayer&rdquo; object (BAP):</p>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0247.1_6A086D46.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0247.1_5F00_6A086D46.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="1" border="0" alt="1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6521.1_thumb_67EB6E7D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6521.1_5F00_thumb_5F00_67EB6E7D.png" width="509" height="233" /></a></p>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">For a non-streaming item being played (e.g. an MP3 in the app&rsquo;s Isolated Storage) this is not a big issue &ndash; to keep the user informed of the brief period before audio starts the app code can watch for the &ldquo;Playing&rdquo; event. In the interim it can display an appropriate message or a ProgressBar to the user.</p>
<p class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F">However for streaming audio this becomes trickier. There are several things to watch for:</p>
<div class="ExternalClass1E1BF82A067F4EB39DF5672C2DED520F"><ol>
<li>The server is not available (because the phone has no working data connection, server is offline or there is no route to the server)</li>
<li>The internet connection is slow to respond or has low bandwidth.</li>
</ol></div>
<h2>&nbsp;</h2>
<h2>Handling not being able to play the remote media</h2>
<h3>Catching the error and stopping the agent from getting into a bad state</h3>
<p>In the case of the agent not being able to find the file to play, the &ldquo;TrackReady&rdquo; event will not be raised, but OnError() will be called in your agent. This is a challenge as your agent will then need to decipher the error and communicate this back to your app code. Assuming that you can communicate this error back to your app code using a static class called &ldquo;BackgroundErrorNotifier&rdquo;, you would need to add the following lines to your agent.</p>
<blockquote>
<pre class="code"><span style="color: blue;">protected override void </span>OnError(<span style="color: #2b91af;">BackgroundAudioPlayer </span>player, <span style="color: #2b91af;">AudioTrack </span>track, <span style="color: #2b91af;">Exception </span>error, <span style="color: blue;">bool </span>isFatal)
{
    <span style="color: blue;">if </span>(isFatal)
    {
        </pre>
<span style="background-color: #ffff00;"><span style="color: #2b91af;">BackgroundErrorNotifier</span>.AddError(error); </span>
<pre class="code">        Abort();
    }
    <span style="color: blue;">else </span>{
        </pre>
<span style="background-color: #ffff00;"><span style="color: #2b91af;">BackgroundErrorNotifier</span>.AddError(error); </span>
<pre class="code">        <span style="color: green;"><span style="background-color: #ffff00;">// force the track to stop</span> </span></pre>
<span style="background-color: #ffff00;">player.Track = <span style="color: blue;">null</span>;</span>
<pre class="code">        NotifyComplete();
    }            
}</pre>
</blockquote>
<p>The <span style="font-family: Courier New;" face="Courier New"><span style="background-color: #ffff00;"><span style="color: #2b91af;"></span></span></span><span style="font-family: Courier New;" face="Courier New"><span style="color: #2b91af;">BackgroundErrorNotifier</span>.AddError</span><span style="font-family: Courier New;" face="Courier New"><span style="background-color: #ffff00;"></span>()</span> method would have to use either Isolated Storage or Local Database to communicate back to the app code as discussed in the previous blog post &ndash; the details of this aren&rsquo;t shown here.</p>
<p>The most important thing to note is that you must set <span style="font-family: Courier New;" face="Courier New">player.Track</span> to <span style="font-family: Courier New;" face="Courier New">null</span>. If you don&rsquo;t do this the agent thinks that there is still a track to play and future calls to agent side BAP&rsquo;s Play() or Pause() methods will cause the agent to crash. Setting the current track to null puts the agent back in a known good state &ndash; however this isn&rsquo;t implemented for you in the Background Audio project template code.</p>
<h3>What does this error mean anyway?</h3>
<p>In this case the <span style="font-family: Courier New;" face="Courier New">Exception</span> is always of type <span style="font-family: Courier New;" face="Courier New">System.Exception</span> with an <span style="font-family: Courier New;" face="Courier New">Exception.Message</span> which corresponds to an error code.</p>
<p>There are a few different error messages you can get depending on what actually went wrong, but they need translating from number form into something more useful if you&rsquo;re going to try and describe to your users what went wrong:</p>
<table style="width: 589px;" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="126"><strong><span style="text-decoration: underline;">Exception.Message</span></strong></td>
<td valign="top" width="140"><strong><span style="text-decoration: underline;">Hex equivalent</span></strong></td>
<td valign="top" width="321"><strong><span style="text-decoration: underline;">Meaning</span></strong></td>
</tr>
<tr>
<td valign="top" width="126">&ldquo;-2147012889&rdquo;</td>
<td valign="top" width="140">80072EE7</td>
<td valign="top" width="321">Can&rsquo;t find the server (e.g. phone is in flight mode)</td>
</tr>
<tr>
<td valign="top" width="126">&ldquo;-2147012696&rdquo;</td>
<td valign="top" width="140">80072FA8</td>
<td valign="top" width="321">No available network connection</td>
</tr>
<tr>
<td valign="top" width="126">"-1072889830&rdquo;</td>
<td valign="top" width="140">C00D001A</td>
<td valign="top" width="321">Can&rsquo;t find media file (e.g. the MP3 file you were pointing to is no longer on the server)</td>
</tr>
<tr>
<td valign="top" width="126">&ldquo;-2147467259&rdquo;</td>
<td valign="top" width="140">80004005</td>
<td valign="top" width="321">Non-specific error code</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h2>Handling slow communications or low bandwidth</h2>
<p>If the server is slow to respond and/or there is only low bandwidth available the &ldquo;TrackReady&rdquo; event will be raised after a few seconds, and the data will take a long time to buffer. One of the apps that came through our Depth Partner Support program has exhibited this problem. The server was based in a different continent from where the app was being tested. Under test we were seeing it took 7-8 seconds before &ldquo;TrackReady&rdquo; event fired and a further 70 seconds before the audio started playing due to the length of time it was taking for the audio to buffer. Once the buffering had stopped the audio stream was playing fine.</p>
<p>Bear the above in mind if you are expecting users of your application to be using audio streams which are hosted on servers which are physically a long way from them.</p>
<p>In this case once &ldquo;TrackReady&rdquo; has been received you know that the Background Audio Zune Media Queue is happy with the file (as otherwise one of the errors described above would have been triggered). That means that there is a valid <span style="font-family: Courier New;" face="Courier New">AudioTrack</span> object that can be used to pass information from agent to the app.</p>
<p>In this scenario you can use the <span style="font-family: Courier New;" face="Courier New">AudioTrack.Tag</span> property string to indicate if the media is buffering or not. Start by setting the Tag to &ldquo;Buffering&rdquo; as soon as the track is created and passed back to the agent side player&hellip;</p>
<blockquote>
<pre class="code"><span style="color: blue;">private </span><span style="color: #2b91af;">AudioTrack </span>GetNextTrack()
{    <span style="color: green;"> // This is an extremely simple agent which plays a single track </span><span style="color: #2b91af;">AudioTrack </span>track = <span style="color: blue;">new </span><span style="color: #2b91af;">AudioTrack</span>(
        <span style="color: blue;">new </span><span style="color: #2b91af;">Uri</span>(
            <span style="color: #a31515;">"https://traffic.libsyn.com/wpradio/WPRadio_52.mp3"</span>), 
            <span style="color: #a31515;">"WP Radio #52"</span>, 
            <span style="color: #a31515;">"WP Radio"</span>, 
            <span style="color: #a31515;">""</span>, 
            <span style="color: blue;">null</span>);        
    <span style="color: green;">// set buffer flag </span>track.BeginEdit();
    track.Tag = <span style="color: #a31515;">"Buffering"</span>;
    track.EndEdit();                                        
    <span style="color: blue;">return </span>track;
}</pre>
</blockquote>
<p>&hellip; and then once the agent finally stops buffering change the Tag to &ldquo;Playing&rdquo; and the app code can tell the track is *really* playing.</p>
<blockquote>
<pre class="code"><span style="color: blue;">protected override void </span>OnPlayStateChanged(<span style="color: #2b91af;">BackgroundAudioPlayer </span>player, <span style="color: #2b91af;">AudioTrack </span>track, <span style="color: #2b91af;">PlayState </span>playState)
{
    <span style="color: blue;">switch </span>(playState)
    {
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.TrackEnded:
            player.Track = GetNextTrack();
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.TrackReady:
            player.Play();
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Shutdown:
            <span style="color: green;">// TODO: Handle the shutdown state here (e.g. save state) </span><span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Unknown:
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Stopped:
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Paused:
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Playing:                 
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.BufferingStarted:
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.BufferingStopped:
            track.BeginEdit();
            track.Tag = <span style="color: #a31515;">"Playing"</span>;
            track.EndEdit();   
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Rewinding:
            <span style="color: blue;">break</span>;
        <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.FastForwarding:
            <span style="color: blue;">break</span>;
    }
    NotifyComplete();
}</pre>
</blockquote>
<p><span>A couple of things to watch for: </span></p>
<ul>
<li><span>firstly you must call BeginEdit() and EndEdit() on the AudioTrack before you modify it. </span></li>
<li>secondly I found you need to set an actual string for the Tag, and can&rsquo;t just use null or the empty string.</li>
</ul>
<h1>Joining this all together in the app code</h1>
<p>In the app code, you will clearly only be able to pick up errors and changes in the AudioTrack.Tag property if the app is in the foreground and running. In fact due to the cost of polling for these changes it is only worth checking for errors when the &ldquo;Now Playing&rdquo; experience of your app is being shown.</p>
<p>In this final sample, it is assumed that you are implementing your &ldquo;Now Playing&rdquo; UI in a dedicated PhoneApplicationPage. That allows you to set up a timer to poll for agent errors and buffering state in OnNavigatedTo. This timer will be stopped in OnNavigatedFrom.</p>
<p>It is assumed that the UI contains a progress bar (<span style="font-family: Courier New;" face="Courier New">progressBar</span>), and a TextBlock for each of the following:</p>
<ul>
<li>Track title (<span style="font-family: Courier New;" face="Courier New">txtTitle</span>)</li>
<li>Track position (<span style="font-family: Courier New;" face="Courier New">txtPosition</span>)</li>
</ul>
<p>The errors are assumed to be retrieved as a single string from a helper class <span style="color: #2b91af;">BackgroundErrorNotifier</span>.GetError()</p>
<pre class="code"><span style="color: blue;">public partial class </span><span style="color: #2b91af;">NowPlayingPage </span>: <span style="color: #2b91af;">PhoneApplicationPage </span>{
    <span style="color: #2b91af;">DispatcherTimer </span>playTimer;
    <span style="color: #2b91af;">EventHandler </span>playTimerTickEventHandler;
    <span style="color: #2b91af;">EventHandler </span>playStateChangedEventHandler;

    <span style="color: blue;">public </span>NowPlayingPage()
    {
        InitializeComponent();
        <span style="color: green;">// create timer and event handlers </span>playTimer = <span style="color: blue;">new </span><span style="color: #2b91af;">DispatcherTimer</span>();
        playTimer.Interval = <span style="color: #2b91af;">TimeSpan</span>.FromMilliseconds(1000);
        playTimerTickEventHandler = <span style="color: blue;">new </span><span style="color: #2b91af;">EventHandler</span>(playTimer_Tick);
        playStateChangedEventHandler = <span style="color: blue;">new </span><span style="color: #2b91af;">EventHandler</span>(Instance_PlayStateChanged);
    }
    
    <span style="color: blue;">protected override void </span>OnNavigatedTo(System.Windows.Navigation.<span style="color: #2b91af;">NavigationEventArgs </span>e)
    {
        <span style="color: blue;">base</span>.OnNavigatedTo(e);
        <span style="color: green;">// register event handlers and start timer </span><span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance.PlayStateChanged += playStateChangedEventHandler;
        playTimer.Tick += playTimerTickEventHandler;
        playTimer.Start();

        <span style="color: green;">// force a UI refresh of the current state of the background audio </span>Instance_PlayStateChanged(<span style="color: blue;">this</span>, <span style="color: blue;">null</span>);            
    }

    <span style="color: blue;">protected override void </span>OnNavigatedFrom(System.Windows.Navigation.<span style="color: #2b91af;">NavigationEventArgs </span>e)
    {
        <span style="color: green;">// stop timer and unregister event handlers </span>playTimer.Stop();
        playTimer.Tick -= playTimerTickEventHandler;
        <span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance.PlayStateChanged -= playStateChangedEventHandler;
        <span style="color: blue;">base</span>.OnNavigatedFrom(e);
    }

    <span style="color: blue;">void </span>playTimer_Tick(<span style="color: blue;">object </span>sender, <span style="color: #2b91af;">EventArgs </span>e)
    {
        <span style="color: green;">// check for errors </span><span style="color: blue;">string </span>errorString = <span style="color: #2b91af;">BackgroundErrorNotifier</span>.GetError();
        <span style="color: blue;">if </span>(errorString != <span style="color: blue;">null</span>)
        {
            <span style="color: #2b91af;">MessageBox</span>.Show(errorString, <span style="color: #a31515;">"Audio error"</span>, <span style="color: #2b91af;">MessageBoxButton</span>.OK);
            progressBar.IsIndeterminate = <span style="color: blue;">false</span>;
        }

        <span style="color: green;">// update UI if audio is active </span><span style="color: blue;">var </span>player = <span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance;
        <span style="color: #2b91af;">AudioTrack </span>currentTrack = player.Track;
        <span style="color: #2b91af;">PlayState </span>bapState = player.PlayerState;
        <span style="color: blue;">if </span>((bapState != <span style="color: #2b91af;">PlayState</span>.Unknown)
            &amp;&amp; (currentTrack != <span style="color: blue;">null</span>))
        {
            <span style="color: #2b91af;">TimeSpan </span>position = player.Position;
            txtPosition.Text = position.ToString(<span style="color: #a31515;">@"hh\:mm\:ss"</span>);
            <span style="color: blue;">if </span>((bapState == <span style="color: #2b91af;">PlayState</span>.Playing) &amp;&amp; 
                (currentTrack.Tag == <span style="color: #a31515;">"Buffering"</span>))
            {
                progressBar.IsIndeterminate = <span style="color: blue;">true</span>;
            }
            <span style="color: blue;">else </span>{
                progressBar.IsIndeterminate = <span style="color: blue;">false</span>;
            }                
        }            
    }

    <span style="color: blue;">void </span>Instance_PlayStateChanged(<span style="color: blue;">object </span>sender, <span style="color: #2b91af;">EventArgs </span>e)
    {
        <span style="color: blue;">var </span>player = <span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance;
        <span style="color: #2b91af;">PlayState </span>bapState = player.PlayerState;
        <span style="color: #2b91af;">AudioTrack </span>track = player.Track;
        <span style="color: blue;">if </span>(track != <span style="color: blue;">null</span>)
        {
            txtTitle.Text = track.Title;
        }
        <span style="color: blue;">else </span>{
            txtTitle.Text = <span style="color: #a31515;">"No track information!"</span>;
        }
        <span style="color: blue;">switch </span>(bapState)
        {
            <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Unknown:
                <span style="color: blue;">break</span>;
            <span style="color: blue;">case </span><span style="color: #2b91af;">PlayState</span>.Playing:                    
            <span style="color: blue;">default</span>:
                progressBar.IsIndeterminate = <span style="color: blue;">false</span>;
                <span style="color: blue;">break</span>;
        }
    }

    <span style="color: blue;">private void </span>btnPlay_Click(<span style="color: blue;">object </span>sender, <span style="color: #2b91af;">RoutedEventArgs </span>e)
    {
        <span style="color: blue;">var </span>player = <span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance;
        <span style="color: blue;">if </span>(player.PlayerState != <span style="color: #2b91af;">PlayState</span>.Playing)
        {
            player.Play();
        }
        <span style="color: blue;">else </span>{
            player.Pause();
        }
        progressBar.IsIndeterminate = <span style="color: blue;">true</span>;
    }

    <span style="color: blue;">private void </span>btnNext_Click(<span style="color: blue;">object </span>sender, <span style="color: #2b91af;">RoutedEventArgs </span>e)
    {
        <span style="color: #2b91af;">BackgroundAudioPlayer</span>.Instance.SkipNext();
        progressBar.IsIndeterminate = <span style="color: blue;">true</span>;  
    }
}</pre>
<h1>Conclusion</h1>
<p>Background audio is a great addition to the Windows Phone SDK in &ldquo;Mango&rdquo;. However as these blog posts have shown some of the implementation details require careful attention in order to get a great user-experience.</p>
<p>Hopefully this blog post series will be useful in helping you achieve that!</p>
<p>&nbsp;</p>
<p>Full source code available for <a href="https://skydrive.live.com/redir.aspx?cid=83c623f8864540c6&amp;resid=83C623F8864540C6!108&amp;parid=83C623F8864540C6!107">download here</a>.</p>
<p>&nbsp;</p>
<p><em>Written by <a href="https://blogs.msdn.com/wpukcoe/archive/tags/Paul+Annetts/default.aspx">Paul Annetts</a></em></p>]]></content:encoded>
    </item>
    <item>
      <title>Background audio in Windows Phone 7.5 (Part 2)</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/background-audio-in-windows-phone-7-5-part-2</link>
      <pubDate>Fri, 10 Feb 2012 10:25:00 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/02/10/background-audio-in-windows-phone-7-5-part-2/</guid>
      <description><![CDATA[The story so far
In the first part of this series on Background Audio the architecture of the...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClass80A9596DEF9D43BE91C1BAD2CED460E7">
<h1>The story so far</h1>
<p>In the <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/09/background-audio-in-windows-phone-7-5-part-1.aspx">first part</a> of this series on Background Audio the architecture of the Background Audio feature of the phone was introduced. The Marketplace Certification guidelines that are relevant to Background Audio were highlighted. Then a code sample explaining how to integrate with the Music and Videos Hub was presented.</p>
<h1>Where we are now</h1>
<p>This part of the series will cover the following topics:</p>
<ul>
<li>How to specify a playlist</li>
<li>Playing your audio: what events occur</li>
<li>Background audio and user feedback in the app</li>
</ul>
<h1>How to specify a playlist and other information</h1>
<p>As we will see in more detail later in this blog post audio track information has to be provided from the agent side, not the app UI side of your code. However of course in most cases the app UI will gather information from the user to specify which audio to play. It is therefore inevitable that there needs to be some communication between the app UI and the agent code.</p>
<h2>Why is data sharing different for background agents compared with normal apps?</h2>
<p>The architecture for background audio application means that the app code and agent code run in different processes and don&rsquo;t have any common memory where they can place shared C#/VB objects.</p>
<p>The advantage of this approach is that this allows the Windows Phone operating system to treat the background audio app UI part as any other app, with the same app lifecycle.</p>
<p>The OS can then call the background agent when required without needing to start the main app: usually when changing tracks or dealing with input from the Universal Volume Control (UVC). That also means that the OS is free to aggressively shutdown agents once the agent&rsquo;s piece work is done - or if the agent is taking too long or using too much RAM or CPU for the OS&rsquo;s liking.</p>
<p>Because of this it is also not possible to predict when the app code and the agent code will run simultaneously so care must be taken when sharing data between the two.</p>
<h2>How to pass data between application code and agent</h2>
<p>There are several ways to pass or share data between the app code and the agent:</p>
<ol>
<li>You can read properties of the BackgroundAudioPlayer (BAP) object to determine the state of the audio agent and current track position and duration.</li>
<li>If the BAP is active for your application (you are playing or paused), then the AudioTrack.Tag property can be used to pass information between app and agent. This is the recommended approach in the <a href="https://msdn.microsoft.com/en-us/library/hh202944(v=vs.92).aspx">Background Agent Best Practices for Windows Phone article on MSDN</a>, however this only works if the background audio is active for your app.</li>
<li>Use Isolated Storage.</li>
<li>Use Local Database.</li>
</ol>
<h2><strong>Challenges for data sharing</strong></h2>
<p>While choosing the right approach, we will face following challenges:</p>
<h3>Challenge 1: Detecting when to read updated information sent from agent to the application:</h3>
<p>(As discussed above the OS controls when the agent code runs so the reverse problem is not something you can do anything about)</p>
<p>For this there are two possibilities:</p>
<ol>
<li>Use state change events raised in the BackgroundAudioPlayer to read information.</li>
<li>Poll the data you&rsquo;re interested in.</li>
</ol>
<h3>Challenge 2: Avoiding accessing the data store at the same time from app code and agent code</h3>
<p>As mentioned above it is possible for app and agent code to run simultaneously and care must be taken to guard against data corruption.</p>
<ol>
<li>Use a Mutex to guard access to Isolated Storage.</li>
<li>Local Database is more robust to simultaneous access like this, but make sure to use a different DataContext every time your agent is launched.</li>
</ol>
<h2>How to share code between application code and agent</h2>
<p>If you use isolated storage or local database APIs to communicate between app code and agent code you will typically need to share code between the app and the agent.</p>
<p>However care must be taken when doing this:</p>
<p>The agent code must not reference a class library which contains banned APIs (even if these are not called from the agent).</p>
<p>To check whether agents are using banned APIs, you can use the <a href="https://msdn.microsoft.com/en-us/library/hh394032(v=vs.92).aspx">Marketplace Test Kit</a> which checks for common faults in Windows Phone applications.</p>
<h1>Playing your audio: what events occur?</h1>
<p>Let&rsquo;s explore how the background audio events are raised &ndash; to do this we will go back to the architecture diagram of background audio introduced in the previous blog post.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6131.BackgroundAudioArchitecture_46B76E3F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6131.BackgroundAudioArchitecture_5F00_46B76E3F.png"><img style="padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="BackgroundAudioArchitecture" border="0" alt="BackgroundAudioArchitecture" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/2402.BackgroundAudioArchitecture_thumb_1D602641.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/2402.BackgroundAudioArchitecture_5F00_thumb_5F00_1D602641.png" width="406" height="417" /></a></p>
<p>Remember, the BackgroundAudioPlayer (BAP) object appears to be the same from both the application side and agent side, however we will see there are some important differences in practice when we look at the events that flow from some common usage scenarios. Let&rsquo;s look at these now:</p>
<h2>App startup &ndash; check what state BAP is in</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0841.1_02475733.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0841.1_5F00_02475733.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="1" border="0" alt="1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/1488.1_thumb_60E7B196.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/1488.1_5F00_thumb_5F00_60E7B196.png" width="460" height="124" /></a></p>
<p>In this case no background audio is playing &ndash; the first surprise is that the app-side BAP returns &ldquo;Unknown&rdquo; state. Clearly there is no need to involve the agent side BAP to check the state of background audio.</p>
<h2>Playing a new track</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0728.2_268C3BB5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0728.2_5F00_268C3BB5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="2" border="0" alt="2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/2477.2_thumb_36B803AE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/2477.2_5F00_thumb_5F00_36B803AE.png" width="536" height="316" /></a></p>
<p>Understanding what is going on in this diagram is critical to understanding how the Background Audio player works. It seems quite complex but it is worth bearing in mind that all of this is implemented for you in the template background audio project. All that remains for the developer is to add their own logic for finding tracks for the agent to play.</p>
<p>Firstly, the app calls the BackgroundAudioPlayer.Instance.Play() method. This will cause the audio agent to start up (and if necessary to load into memory which can clearly be seen if you are using the debugger).</p>
<p>Once loaded the agent code will receive the Play user action &ndash; and it should respond by calling the Play method on the agent side BAP.</p>
<p>In response to a Play() request with no track set, the agent side BAP will raise the TrackEnded event on the agent. At this point your agent code should find the next track to play (if it is available). The agent then needs to set the Track property on the agent-side BAP.</p>
<p>Once the BAP has made the track ready to play the agent receives the TrackReady event. In response to this the agent should call Play() to start playback of the new track.</p>
<p>At this point, the app code should receive the Playing event (if it is registered to receive BAP events).</p>
<p>And the audio should start playing &ndash; there are a couple of further events on the agent side, BufferingStopped and Playing which are only significant for streaming audio scenarios which will be expanded upon in the next blog post.</p>
<h2>Play/Pause during playback</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6685.3_49F8BA4D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6685.3_5F00_49F8BA4D.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="3" border="0" alt="3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3122.3_thumb_6143BEBE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3122.3_5F00_thumb_5F00_6143BEBE.png" width="460" height="364" /></a></p>
<p>These actions are fairly straightforward as expected.</p>
<h2>Skip to next track</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6266.4_4AA17077.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6266.4_5F00_4AA17077.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="4" border="0" alt="4" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3603.4_thumb_24CB4A14.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3603.4_5F00_thumb_5F00_24CB4A14.png" width="537" height="281" /></a></p>
<h2>Track comes to an end: find new track (no user action)</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6811.5_4C42167E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6811.5_5F00_4C42167E.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="5" border="0" alt="5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7384.5_thumb_5F82CD1D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7384.5_5F00_thumb_5F00_5F82CD1D.png" width="509" height="233" /></a></p>
<p>These diagrams is similar to the initial playback case &ndash; when the agent receives the SkipNext user action or TrackEnded event it should find the new track to play, and set the Track property on the agent-side BAP.</p>
<p>However note that there is an Unknown state reported to the app when there is a change of tracks. This creates a potential challenge for the app UI to display the correct currently playing track information.</p>
<h1>Background audio and user feedback in the app</h1>
<p>The MSDN docs which state that the audio agent gives no guarantee as to how long it will take for a command like Play() to be processed. It could take a few seconds to get the Playing event after the play command (even for non-streaming audio).</p>
<p>This is a challenge in the context of Marketplace Certification requirement 5.1.3</p>
<blockquote>
<p>5.1.3 Application Responsiveness</p>
<p>If an application performs an operation that causes the device to appear to be unresponsive for more than three seconds, such as downloading data over a network connection, the application must display a visual progress or busy indicator.</p>
</blockquote>
<p>In this case if no steps are taken the user will likely think that the app has ignored the tap which they were expecting to start or pause the audio. In our Depth Partner Support program we have seen a few such applications which use the Background Audio feature which suffer from this.</p>
<p>For good user experience once a play/pause control has been pressed:</p>
<ul>
<li>the app should display a ProgressBar in the Indeterminate state immediately to indicate to the user that the app has registered your command. It should turn off the ProgressBar once the Playing/Pausing event has been received.</li>
<li>the app should disable or &ldquo;grey out&rdquo; any controls that will lead to commands to BackgroundAudioPlayer object &ndash; if multiple commands are sent these will be queued and this can become tricky to deal with given the delay in response from the BAP, leading to the app code getting in the wrong state or even crashing.</li>
</ul>
<h2>Telling the user the track position</h2>
<p>If you are in the &ldquo;Now Playing&rdquo; experience of your app you may want to have a control on your page which tells the user the current track location. This can be simply achieved by calling BackgroundAudioPlayer.Instance.Position method in the callback of a DispatcherTimer.</p>
<h1>What next?</h1>
<p>The <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/11/background-audio-in-windows-phone-7-5-part-3.aspx">next part</a> of this blog series will deal with challenges with streaming audio.</p>
<p><em>Written by</em> <a href="https://blogs.msdn.com/wpukcoe/archive/tags/Paul+Annetts/default.aspx">Paul Annetts</a></p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Background audio in Windows Phone 7.5 (Part 1)</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/background-audio-in-windows-phone-7-5-part-1</link>
      <pubDate>Thu, 09 Feb 2012 09:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/02/09/background-audio-in-windows-phone-7-5-part-1/</guid>
      <description><![CDATA[Summary
Using background audio for Windows Phone 7.5 is a great way of playing audio content such...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClassE42F3AEE2E5544518A5F62D8A808D087">
<h1>Summary</h1>
<p>Using background audio for Windows Phone 7.5 is a great way of playing audio content such as internet radio stations, podcasts and music tracks even when your application is no longer in the foreground and when the phone is locked.</p>
<p>This series of blog posts will help you get the most of the capabilities of this new &ldquo;Mango&rdquo; feature and to avoid several gotchas associated with it.</p>
<h1>What are we covering in these blog posts</h1>
<p>This first post will start with some introduction to the Background Audio, how to get started, the Marketplace Certification requirements and how to integrate your background audio app with the Music+Videos Hub on the phone.</p>
<p>The <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/10/background-audio-in-windows-phone-7-5-part-2.aspx">second post</a> will deal with some implementation advice on how to specify a playlist and look in more detail at how a Background Audio app works.</p>
<p>The <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/11/background-audio-in-windows-phone-7-5-part-3.aspx">third post</a> will discuss particular challenges of keeping a great user experience when playing audio files which are streamed from a remote server.</p>
<h1>Getting Started with Background Audio</h1>
<p>A good first place to look for advice if you&rsquo;re new to a Windows Phone feature is on MSDN. In particular there is a great overview <a href="https://msdn.microsoft.com/en-us/library/hh394039(v=vs.92).aspx">of background audio here</a>. This includes a code-walkthrough which will get you to create a simple project with a foreground application and a background audio agent which is responsible for providing audio to the Zune Media Queue. The Windows Phone 7.1 SDK sample for background audio can be found <a href="https://go.microsoft.com/fwlink/?LinkId=219073">here</a>. And the sample for this article series can be downloaded from this <a href="https://skydrive.live.com/redir.aspx?cid=83c623f8864540c6&amp;resid=83C623F8864540C6!108&amp;parid=83C623F8864540C6!107">location</a>.</p>
<p>This MSDN article also has a good architectural diagram for Background Audio as shown below.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7181.BackgroundAudioArchitecture_4A889E6E.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7181.BackgroundAudioArchitecture_5F00_4A889E6E.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="BackgroundAudioArchitecture" border="0" alt="BackgroundAudioArchitecture" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3884.BackgroundAudioArchitecture_thumb_7A63402F.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3884.BackgroundAudioArchitecture_5F00_thumb_5F00_7A63402F.png" width="410" height="420" /></a></p>
<p>For the purpose of these blog posts, it is assumed that you are writing &ldquo;Background Audio Playlist Application&rdquo; rather than the more complex &ldquo;Background Audio Streaming Application&rdquo;.</p>
<h2>BackgroundAudioPlayer (BAP)</h2>
<p><a title="https://msdn.microsoft.com/en-us/library/microsoft.phone.backgroundaudio.backgroundaudioplayer(v=VS.92).aspx" href="https://msdn.microsoft.com/en-us/library/microsoft.phone.backgroundaudio.backgroundaudioplayer(v=VS.92).aspx">(BackgroundAudioPlayer MSDN class reference link)</a></p>
<p>As can be seen from the architecture diagram the BackgroundAudioPlayer (BAP) is the key to understanding the background audio feature.</p>
<p>However notice from the diagram that the Application UI code (&ldquo;app code&rdquo;) is isolated from the AudioPlayerAgent code (&ldquo;agent code&rdquo;), via the Zune Media Queue. This is easy to overlook as from both app code and agent code perspective, it appears they are sharing the same BAP object.</p>
<h2>Universal Volume Control (UVC)</h2>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7673.BackgroundAudioUVCImage_2CE69DA2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7673.BackgroundAudioUVCImage_5F00_2CE69DA2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="BackgroundAudioUVCImage" border="0" alt="BackgroundAudioUVCImage" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3750.BackgroundAudioUVCImage_thumb_1D638BD3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3750.BackgroundAudioUVCImage_5F00_thumb_5F00_1D638BD3.png" width="488" height="218" /></a></p>
<p>The Universal Volume Control (UVC) allows the user to control any audio playing in the background (whether it is from Zune, IE or your app). It allows users to play, pause, rewind, fast-forward and skip and also launch your application for more in-depth control of the audio that is playing. It also displays the current playing track title and author. In the case of the picture of the UVC above it can be seen from the icon before the title that the phone is streaming audio content from a remote server. This streaming icon is automatically added by the phone OS if you are playing from a remote server, rather than playing from your app&rsquo;s Isolated Storage.</p>
<h1>Background Audio Marketplace Certification requirements</h1>
<p>As with any other Windows Phone feature it&rsquo;s worth checking out the Marketplace Certification Requirements early in your development to check what you are allowed to do and what is required of your application which uses a particular feature. The Marketplace certification requirements can be found on <a href="https://msdn.microsoft.com/en-us/library/hh184843(v=VS.92).aspx">MSDN here</a>. For the Background Audio feature, the relevant sections are under <a href="https://msdn.microsoft.com/en-us/library/hh184838(v=vs.92).aspx">&ldquo;Additional Requirements for Specific Application types&rdquo;</a>.</p>
<h2>Music and Videos Hub integration</h2>
<p>Firstly you have a choice to make for your application: should it be registered to the Music and Videos Hub or not? Summarizing this choice focusing on technical issues:</p>
<table style="width: 722px;" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="151"><strong>Certification Section</strong></td>
<td valign="top" width="257"><strong>Non-Music and Video Hub app</strong></td>
<td valign="top" width="312"><strong>Music and Video Hub app</strong></td>
</tr>
<tr>
<td valign="top" width="154">6.4 Music + Videos Hub Application</td>
<td valign="top" width="256">Not applicable</td>
<td valign="top" width="310">Must comply, in particular watch out for: <br />6.4.2 - Music + Videos Hub History and Now Playing List Functionality <br />6.4.3 - Music + Videos Hub History List Updates <br />6.4.4 - Music + Videos Hub New List Updates </td>
</tr>
<tr>
<td valign="top" width="156">6.5 Non Music + Videos Hub Applications That Play Media</td>
<td valign="top" width="255">Must comply, in particularly watch out for: <br />6.5.1 &ndash; Initial Launch Functionality <br />6.5.2 - Configurable Functionality <br />6.5.3 - Applications that Play a Video or Audio Segment</td>
<td valign="top" width="310">Not applicable</td>
</tr>
</tbody>
</table>
<p>In this series we will focus on music application which implements background audio playback and integrates into Music and Video hub on the phone.</p>
<h2>Background Audio Marketplace Certification Requirements</h2>
<p>The additional requirements for Background Audio in section 6.9 are fairly straightforward to adhere to if you follow a few key design principles for the Background Audio player.</p>
<table style="width: 664px;" border="1" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="206"><strong><span style="text-decoration: underline;">Requirement</span></strong></td>
<td valign="top" width="456"><strong><span style="text-decoration: underline;">Design Principle</span></strong></td>
</tr>
<tr>
<td valign="top" width="208">6.9.1- User Initiated Background Audio</td>
<td valign="top" width="455">All audio should be started by the user (not automatically from code)</td>
</tr>
<tr>
<td valign="top" width="209">6.9.2 &ndash; Stopping Background Audio</td>
<td valign="top" width="454">User should be able to find the playback controls easily</td>
</tr>
<tr>
<td valign="top" width="210">6.9.3 &ndash; Universal Volume Control Commands</td>
<td valign="top" width="453">UVC should be able to control the audio when the app isn&rsquo;t running in the foreground</td>
</tr>
<tr>
<td valign="top" width="211">6.9.4 &ndash; Universal Volume Control Strings</td>
<td valign="top" width="452">UVC content should be relevant</td>
</tr>
<tr>
<td valign="top" width="212">6.9.5 &ndash; Background Audio Streaming Agent</td>
<td valign="top" width="452">(Not applicable for a AudioPlayerAgent which only tells the Zune Media Queue which file or URL to play) <br />Streaming agent should only contain code relevant to streaming</td>
</tr>
</tbody>
</table>
<p>These aren&rsquo;t technical issues so we won&rsquo;t cover them any more in these blog posts &ndash; however it is clear that your application design should meet all of these requirements.</p>
<h1>Integrating with the Music+Videos Hub on the phone</h1>
<p>If you have decided to integrate with the Music+Video hub,&nbsp; the following MSDN link contains details how to achieve that: &ldquo;<a href="https://msdn.microsoft.com/en-us/library/ff769558(v=VS.92).aspx">How to: Integrate with the Music and Videos Hub for Windows Phone</a>&rdquo;.</p>
<p>To summarize this page you will need to:</p>
<ol>
<li>Test the integration on a physical Windows Phone device (the emulator doesn&rsquo;t have the Music + Videos Hub).</li>
<li>Update your Application Manifest file to be able to test the Hub integration.</li>
<li>Update the &lsquo;Now Playing&rsquo; tile (do this from the background agent when switching between tracks as it&rsquo;s the only way to keep it accurate)</li>
<li>Update the &lsquo;History&rsquo; list</li>
<li>Update the &lsquo;New&rsquo; list</li>
</ol>
<p>It is worth noting that when providing icons for your audio to the Music + Videos Hub these must be local to the device, and therefore be either part of the application XAP or be found in the application&rsquo;s Isolated Storage. This ensures that the phone will always be able to show an image in the Music + Videos Hub, even if your device is disconnected from the internet, or if images are not available on a remote server.</p>
<h2>Integration between the Music hub and your app&rsquo;s &ldquo;playback experience&rdquo;</h2>
<p>A lot of the technical detail you will need to integrate your app and the Music Hub is covered in the MSDN page above, however it is worth expanding on how to achieve the integration between the Music and Video hub and your application&rsquo;s &ldquo;playback experience&rdquo;.</p>
<p>Consider Marketplace Requirement 6.4.2:</p>
<blockquote>
<p>When a user taps a tile associated with the application in the History or Now Playing list of the Music + Videos Hub, the application must either (a) launch the playback experience for the content identified in the tile, or (b) launch a view that provides information about the previously played media content and allows the user to resume. The application must not launch to the main or default landing page when the user taps on a content tile in the History, Now Playing, or New list of the Music + Videos Hub.</p>
</blockquote>
<p>It is worth breaking down the Now Playing scenario:</p>
<ol>
<li>User initiates playback from the UI</li>
<li>The agent code will provide an AudioTrack to the BAP which describes the audio to play. This will be used to set up the UVC and start playback.</li>
<li>At the same time the agent code should inform the Music and Videos Hub about the track that is currently playing (and add it to the history).</li>
<li>User can at a later time tap the Now Playing tile (or the UVC track title which will use the same information).</li>
</ol>
<p>If you skip step 3 then your application will launch, but only on the main page, and your app will fail requirement 6.4.2.</p>
<p>To fix this you will need to pass in PlayerContext to the MediaHistoryItem so that you can detect on application launch that this is a special launch from the Music + Videos Hub or the UVC.</p>
<p>For example, for a very simple agent which just plays a single episode of a web radio, and uses a file &ldquo;Image.png&rdquo; as the media image to be displayed in the Music + Videos Hub:</p>
<blockquote>
<p><span style="color: blue;">protected override void </span>OnPlayStateChanged( <br />&nbsp;&nbsp;&nbsp; BackgroundAudioPlayer player, <br />&nbsp;&nbsp;&nbsp; AudioTrack track, <br />&nbsp;&nbsp;&nbsp; PlayState playState) <br />{ <br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">switch </span>(playState) <br />&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">case </span>PlayState.TrackEnded: <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; player.Track = GetNextTrack(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">break</span>; <br /><br />... <br /><br /><span style="color: blue;">private </span>AudioTrack GetNextTrack() <br />{ <br />&nbsp;&nbsp;&nbsp; <span style="color: green;">// set the next track - in this case one hardcoded track <br />&nbsp;&nbsp;&nbsp; </span>AudioTrack track = <span style="color: blue;">new </span>AudioTrack( <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">new </span>Uri(<span style="color: #a31515;">"https://traffic.libsyn.com/wpradio/WPRadio_52.mp3"</span>), <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #a31515;">"WP Radio #52"</span>, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #a31515;">"WP Radio"</span>, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #a31515;">""</span>, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">null</span>); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <span style="color: green;">// get the stream of "Image.png" which is in the application XAP as Content <br />&nbsp;&nbsp;&nbsp; </span>StreamResourceInfo sri = Application.GetResourceStream( <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue;">new </span>Uri(<span style="color: #a31515;">"Image.png"</span>, UriKind.Relative)); <br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">using </span>(<span style="color: #2b91af;">Stream </span>imageStream = sri.Stream) <br />&nbsp;&nbsp;&nbsp; { <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MediaHistoryItem nowPlayingItem = <span style="color: blue;">new </span>MediaHistoryItem(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nowPlayingItem.Title = track.Title; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nowPlayingItem.PlayerContext.Add(<span style="color: #a31515;">"LaunchNowPlaying"</span>, <span style="color: #a31515;">"true"</span>); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nowPlayingItem.ImageStream = imageStream; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MediaHistory.Instance.NowPlaying = nowPlayingItem; <br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green;">// reuse the same image stream for recent item, need to reset it first however <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>imageStream.Seek(0, <span style="color: #2b91af;">SeekOrigin</span>.Begin); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MediaHistoryItem recentItem = <span style="color: blue;">new </span>MediaHistoryItem(); <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recentItem.Title = track.Title; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; recentItem.PlayerContext.Add(<span style="color: #a31515;">"LaunchRecentItem"</span>, <span style="color: #a31515;">"1"</span>);&nbsp; <span style="color: green;">// put an ID of the recent item to add <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>recentItem.ImageStream = imageStream; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MediaHistory.Instance.WriteRecentPlay(recentItem);&nbsp; <br />&nbsp;&nbsp;&nbsp; } <br />&nbsp;&nbsp;&nbsp; <span style="color: blue;">return </span>track; <br />} </p>
</blockquote>
<p>To complete the integration, in main application&rsquo;s initial page code-behind (e.g. MainPage.xaml.cs) you need to detect that the application was launched from the Music + Videos Hub or the UVC. Here is a simple example which works with the PlayerContext set in the agent code sample above.</p>
<blockquote>
<pre class="code"><span style="color: blue;">protected override void </span>OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    <span style="color: blue;">var </span>queryString = NavigationContext.QueryString;
    <span style="color: blue;">string </span>queryStringValue;
    <span style="color: blue;">if </span>(queryString.TryGetValue(<span style="color: #a31515;">"LaunchNowPlaying"</span>, <span style="color: blue;">out </span>queryStringValue))
    {
        MessageBox.Show(<span style="color: #a31515;">"LaunchNowPlaying is " </span>+ queryStringValue, 
            <span style="color: #a31515;">"Launch from UVC / Hub Now Playing!"</span>, 
            MessageBoxButton.OK);
        <span style="color: green;">// TODO: navigate to "Now Playing" experience </span>}
    <span style="color: blue;">else if </span>(queryString.TryGetValue(<span style="color: #a31515;">"LaunchRecentItem"</span>, <span style="color: blue;">out </span>queryStringValue))
    {
        MessageBox.Show(<span style="color: #a31515;">"LaunchRecentItem is " </span>+ queryStringValue,
            <span style="color: #a31515;">"Launch from Hub Recent item"</span>,
            MessageBoxButton.OK);
        <span style="color: green;">// TODO: Find the item specified, start playing it, navigate to "Now Playing" experience </span>}
    <span style="color: blue;">else </span>{
        MessageBox.Show(<span style="color: #a31515;">"Normal launch"</span>, <span style="color: #a31515;">"Normal launch"</span>, MessageBoxButton.OK);
    }
}</pre>
</blockquote>
<p>In an application using the MVVM pattern you should pass down the navigation query string from the View to the ViewModel in a message &ndash; this will stop you having too much application logic in the View class.</p>
<h1>What next</h1>
<p>This blog post explained the principles needed to implement a Background Audio agent which will meet the Marketplace Certification requirements and will be integrated to the Music and Videos Hub on the phone.</p>
<p>The <a href="https://blogs.msdn.com/b/wpukcoe/archive/2012/02/10/background-audio-in-windows-phone-7-5-part-2.aspx">next</a> blog post in this series will tackle further implementation strategies for a background audio player application.</p>
<p></p>
<p><em>Written by</em> <a href="https://blogs.msdn.com/wpukcoe/archive/tags/Paul+Annetts/default.aspx">Paul Annetts</a></p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Common Marketplace ingestion errors and how to avoid them</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/common-marketplace-ingestion-errors-and-how-to-avoid-them</link>
      <pubDate>Fri, 20 Jan 2012 10:39:06 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/01/20/common-marketplace-ingestion-errors-and-how-to-avoid-them/</guid>
      <description><![CDATA[Ingestion is the process of testing, code signing, and publishing your application via Microsoft's...]]></description>
      <content:encoded><![CDATA[<p>Ingestion is the process of testing, code signing, and publishing your application via Microsoft's <a href="https://create.msdn.com">App Hub</a> to the <a href="https://www.windowsphone.com/en-US/marketplace">Windows Phone Marketplace</a>. </p>  <p>In this blog post we’ll review three of the most common errors seen by developers when submitting their applications to App Hub. The errors are:</p>  <p><strong>Error: &quot;An update cannot support fewer languages than the previous app instance supported (1047)&quot;</strong></p>  <p><strong>Error: “The [NeutralResourcesLanguage] attribute is missing on the entry assembly. (2003)”</strong>.</p>  <p><strong>Error: “An error occurred connecting to the server”.</strong></p>  <p>When you submit your application to <a href="https://create.msdn.com/">App Hub</a>, it is immediately run through a series of static tests. If your application passes these tests, App Hub will navigate to the next step in the submission process. If it fails, you will see the static validation error message(s), for example:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3718.image_713FF099.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3718.image_5F00_713FF099.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/5140.image_thumb_492D417A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/5140.image_5F00_thumb_5F00_492D417A.png" width="454" height="480" /></a></p>  <p>Some of the tests done by App Hub are the very same tests you can and should do yourself using the <a href="https://msdn.microsoft.com/en-us/library/hh394032(v=vs.92).aspx">Marketplace Test Kit</a>. The Marketplace Test Kit is installed as a Visual Studio extension when installing the <a href="https://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=27570">Windows Phone SDK</a>. You can start it by right clicking on your project and selecting ‘Marketplace Test Kit’.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0257.image_7A4C7C1A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0257.image_5F00_7A4C7C1A.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6521.image_thumb_59590973.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6521.image_5F00_thumb_5F00_59590973.png" width="454" height="468" /></a></p>  <h3><strong>Error: &quot;An update cannot support fewer languages than the previous app instance supported (1047)&quot;</strong></h3>  <p>One of the static tests not run by the Marketplace Test Kit is for application update language consistency. When you update an application, your update must contain at least the same languages supported by the original. This applies even if your application is not localized. That is, you can add to the number of languages supported, but you cannot remove languages. One side effect of this requirement is that many developers have hit the error, &quot;<strong>An update cannot support fewer languages than the previous app instance supported (1047)&quot;</strong>. This error is often caused by an incorrect English setting. In App Hub there are two English locale groups, North American English and International English. (See here for more information: <a href="https://forums.create.msdn.com/forums/t/87638.aspx">https://forums.create.msdn.com/forums/t/87638.aspx</a>). North American English includes Canadian English and American English. All other ‘English’ languages fall under International English. You will get this error if you update an application that was designated as North American English originally and was updated as International English.</p>  <p>So how is the language specified? The language is specified in your project settings. Note that all applications must specify a neutral language or your app will fail the static test with the error: <strong>“The [NeutralResourcesLanguage] attribute is missing on the entry assembly. (2003)”</strong>. This is the ‘Neutral Language’ assembly setting in Project settings as shown below.</p>  <p>1. Right Click on your project in Solution Explorer </p>  <p>2. Application | Assembly Information. . . </p>  <p>3. Neutral Language </p>  <p>4. Pick a specific default language. For example for English:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3301.image_261CD00A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3301.image_5F00_261CD00A.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/5531.image_thumb_6C2D8D1D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/5531.image_5F00_thumb_5F00_6C2D8D1D.png" width="404" height="384" /></a></p>  <p>In the above example, the neutral language is ‘English’. English without any modifier, is interpreted as ‘International English’ by App Hub.</p>  <p><strong>The July 2011 Marketplace Update.</strong> If you are updating a 7.0 application that was published prior to July 2011, you may run into the ‘fewer languages’ error since applications were not required to specify a default language. The default language was specified by the developer in App Hub. This setting is now automatic. For example, your 1.0 version may be specified as North American English. Therefore, in your update, the neutral language should be specified as</p>  <p>English (Canada)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [assembly: NeutralResourcesLanguage(&quot;en-ca&quot;)]</p>  <p>or</p>  <p>English (United States)&#160; [assembly: NeutralResourcesLanguage(&quot;en-us&quot;)]</p>  <p>If specified as [assembly: NeutralResourcesLanguage(&quot;en&quot;)], you will see the error, <strong>&quot;An update cannot support fewer languages than the previous app instance supported (1047)&quot;</strong>. This is because ‘en’ denotes International English and your update is North American English. Note that English is the only language divided into two groups within App Hub.</p>  <p>You can also see the 'fewer languages' error, if you have a custom build step which uses a macro to modify the AssemblyInfo.cs file. For example: [assembly: NeutralResourcesLanguage(&quot;$currentVsCulture$&quot;)]</p>  <h3><strong>Error: “An error occurred connecting to the server”</strong>. </h3>  <p>You may see this error while uploading your XAP file to App Hub and any of the following are true:</p>  <ol>   <li>Your XAP filename has a period in it. For example: <strong>My.App.XAP</strong>. </li>    <li>Your application contains support for languages which are not supported, or are not properly specified. For example, the Arabic and Hindi languages are currently not supported. Submitting an app with these resources, will generate this error. </li>    <li>The neutral language set to one that is not supported by Windows Phone. For example, setting the neutral language to ‘et’ (Estonian) which is not supported in Windows Phone. Here’s a list of the supported languages updated for Windows Phone 7.5: <a href="https://msdn.microsoft.com/en-us/library/hh202918">https://msdn.microsoft.com/en-us/library/hh202918</a> </li> </ol>  <p>Note that in a future update of App Hub, this error message will more accurately reflect the cause of the error.</p>  <p><em>Written by </em><a href="https://blogs.msdn.com/b/wpukcoe/archive/tags/Mike+Francis/default.aspx" target="_blank">Mike Francis</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Designing Touch Targets</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/designing-touch-targets</link>
      <pubDate>Fri, 20 Jan 2012 03:26:39 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/01/20/designing-touch-targets/</guid>
      <description><![CDATA[&#160;    A common problem in Windows Phone app design is the poor use of touch targets, i.e. the...]]></description>
      <content:encoded><![CDATA[<div class="ExternalClass78DDCC41341A4181A908226A48421DE9">   <p>&#160;</p>    <p>A common problem in Windows Phone app design is the poor use of touch targets, i.e. the area of the screen which responds to user interaction (usually a tap). When designing on the emulator, this is easy to overlook as the mouse gives a very precise ‘touch’. However, when the application is run on a device the user’s finger or thumb is normally used to tap on the screen. This is the ‘fat finger’ problem and can mean that items are difficult to hit accurately (user accidentally taps the item next to the desired one) or items that can be tapped on don’t always respond. </p>    <p>&#160;</p>    <p><strong>SIZE AND SPACING</strong> </p>    <p>When touch targets are very small and close together, the user has to take care when tapping to make sure that they accurately hit the item they want. This can be very frustrating and slows down the interaction with the app.</p>    <p>For more detailed guidance for designing touch targets, visit <a href="https://msdn.microsoft.com/en-us/library/hh202889(v=vs.92).aspx"><u>Interactions and Usability with Windows Phone</u></a>.       <br />However, here is a simple walk-through you can try out yourself for an idea of how this works in practice.</p>    <p>Let’s use the ListPicker control from the Silverlight Toolkit for Windows Phone as an example.      <br />On the left is the full screen view where the list uses default TextBlocks to display the items. On the right is the same list, but this time with the FontSize set to “40” and the Margin set to “0,12”.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/1121.ListPicker_FullMode_combo_21462764.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/1121.ListPicker_5F00_FullMode_5F00_combo_5F00_21462764.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="ListPicker_FullMode_combo" border="0" alt="ListPicker_FullMode_combo" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7220.ListPicker_FullMode_combo_thumb_5F5F4215.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7220.ListPicker_5F00_FullMode_5F00_combo_5F00_thumb_5F00_5F5F4215.png" width="489" height="404" /></a></p>    <p>Here’s the code for the ListPicker:     <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" class="wlWriterSmartContent"></div>   </p>    <div style="border-bottom: #000080 1px solid; border-left: #000080 1px solid; font-family: &quot;courier new&quot;, courier, monospace; color: #000; font-size: 10pt; border-top: #000080 1px solid; border-right: #000080 1px solid">     <div style="padding-bottom: 2px; padding-left: 5px; padding-right: 5px; font-family: verdana, tahoma, arial, sans-serif; background: #000080; color: #fff; font-weight: bold; padding-top: 2px">Code Snippet</div>      <div style="background: #ddd; max-height: 300px; overflow: auto">       <ol style="padding-bottom: 0px; margin: 0px 0px 0px 2.5em; padding-left: 5px; padding-right: 0px; background: #ffffff; padding-top: 0px">         <li><span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">toolkit</span><span style="color: #0000ff">:</span><span style="color: #a31515">ListPicker</span><span style="color: #ff0000"> Header</span><span style="color: #0000ff">=&quot;FullScreen ListPicker&quot;</span><span style="color: #ff0000"> ExpansionMode</span><span style="color: #0000ff">=&quot;FullscreenOnly&quot;&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 1</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li>&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 2</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 3</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li>&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 4</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 5</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li>&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span><span style="color: #a31515">List Item 6</span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">sys</span><span style="color: #0000ff">:</span><span style="color: #a31515">String</span><span style="color: #0000ff">&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">toolkit</span><span style="color: #0000ff">:</span><span style="color: #a31515">ListPicker.FullModeItemTemplate</span><span style="color: #0000ff">&gt;</span> </li>          <li>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">DataTemplate</span><span style="color: #0000ff">&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">StackPanel</span><span style="color: #ff0000"> Orientation</span><span style="color: #0000ff">=&quot;Horizontal&quot;&gt;</span> </li>          <li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;</span><span style="color: #a31515">TextBlock</span><span style="color: #ff0000"> Text</span><span style="color: #0000ff">=&quot;{</span><span style="color: #a31515">Binding}</span><span style="color: #0000ff">&quot;</span><span style="color: #ff0000"> FontSize</span><span style="color: #0000ff">=&quot;40&quot;</span><span style="color: #ff0000"> Margin</span><span style="color: #0000ff">=&quot;0,12&quot;/&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">StackPanel</span><span style="color: #0000ff">&gt;</span> </li>          <li>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">DataTemplate</span><span style="color: #0000ff">&gt;</span> </li>          <li style="background: #f3f3f3">&#160;&#160;&#160; <span style="color: #a31515"></span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">toolkit</span><span style="color: #0000ff">:</span><span style="color: #a31515">ListPicker.FullModeItemTemplate</span><span style="color: #0000ff">&gt;</span> </li>          <li><span style="color: #a31515"></span><span style="color: #0000ff">&lt;/</span><span style="color: #a31515">toolkit</span><span style="color: #0000ff">:</span><span style="color: #a31515">ListPicker</span><span style="color: #0000ff">&gt;</span> </li>       </ol>     </div>   </div>    <p>&#160;</p>    <p>While items in both lists are easy to hit with a mouse on the emulator, the list items on the right are much easier to tap accurately on the device. Test this by holding the device in one hand and using your thumb to pick from the list.</p>    <p>&#160;</p>    <p><strong>SCOPE</strong></p>    <p>Sometimes when tapping on items in a list the application does not respond. Despite the item itself appearing large enough to be an easy hit target, in practice the user has to tap several times to get the item to action.</p>    <p>The simple rule is to place the tap event at the highest meaningful control level. Let's look at an example. Suppose our list item uses the following code:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:523124bb-993f-4c48-aed5-66ec1bcd3c68" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ListBoxItem</span><span style="color:#ff0000"> toolkit</span><span style="color:#0000ff">:</span><span style="color:#ff0000">TiltEffect.IsTiltEnabled</span><span style="color:#0000ff">=&quot;True&quot; &gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">=&quot;Horizontal&quot;&gt;</span></li> <li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Image</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;0&quot;</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">=&quot;80&quot;</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">=&quot;80&quot;</span><span style="color:#ff0000"> Source</span><span style="color:#0000ff">=&quot;books.jpg&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;16&quot;/&gt;</span></li> <li style="background: #f3f3f3">        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;1&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;0&quot;&gt;</span></li> <li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;TEST TITLE 1&quot;</span><span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">=&quot;Segoe WP Black&quot;</span><span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">=&quot;48&quot;/&gt;</span></li> <li style="background: #f3f3f3">            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;test sub title 1&quot;</span><span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">=&quot;32&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;0,-12&quot;</span><span style="color:#ff0000"> Tap</span><span style="color:#0000ff">=&quot;TextBlock_Tap&quot; /&gt;</span></li> <li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">StackPanel</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">StackPanel</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ListBoxItem</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p>&#160;</p>    <p>This means only a small part of the ListBoxItem is actually listening for the tap event, but this is not obvious to the user. The red boxed area below shows the part of the item the user has to tap on:</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/4263.Test_ListItem_poor_target_16C55344.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/4263.Test_5F00_ListItem_5F00_poor_5F00_target_5F00_16C55344.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Test_ListItem_poor_target" border="0" alt="Test_ListItem_poor_target" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6242.Test_ListItem_poor_target_thumb_0DF54AF8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6242.Test_5F00_ListItem_5F00_poor_5F00_target_5F00_thumb_5F00_0DF54AF8.png" width="244" height="404" /></a></p>    <p>To make the list items feel more responsive, move the tap event up to the top level component of the ListBoxItem:</p>    <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:179d619a-7d02-4997-a1d9-968a9cd49227" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div> <div style="background: #ddd; max-height: 300px; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#0000ff">&lt;</span><span style="color:#a31515">ListBoxItem</span><span style="color:#ff0000"> toolkit</span><span style="color:#0000ff">:</span><span style="color:#ff0000">TiltEffect.IsTiltEnabled</span><span style="color:#0000ff">=&quot;True&quot;</span><span style="color:#ff0000"> Tap</span><span style="color:#0000ff">=&quot;ListBoxItem_Tap&quot;&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Orientation</span><span style="color:#0000ff">=&quot;Horizontal&quot;&gt;</span></li> <li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">Image</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;0&quot;</span><span style="color:#ff0000"> Width</span><span style="color:#0000ff">=&quot;80&quot;</span><span style="color:#ff0000"> Height</span><span style="color:#0000ff">=&quot;80&quot;</span><span style="color:#ff0000"> Source</span><span style="color:#0000ff">=&quot;books.jpg&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;16&quot;/&gt;</span></li> <li style="background: #f3f3f3">        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">StackPanel</span><span style="color:#ff0000"> Grid.Column</span><span style="color:#0000ff">=&quot;1&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;0&quot;&gt;</span></li> <li>            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;TEST TITLE 1&quot;</span><span style="color:#ff0000"> FontFamily</span><span style="color:#0000ff">=&quot;Segoe WP Black&quot;</span><span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">=&quot;48&quot;/&gt;</span></li> <li style="background: #f3f3f3">            <span style="color:#a31515"></span><span style="color:#0000ff">&lt;</span><span style="color:#a31515">TextBlock</span><span style="color:#ff0000"> Text</span><span style="color:#0000ff">=&quot;test sub title 1&quot;</span><span style="color:#ff0000"> FontSize</span><span style="color:#0000ff">=&quot;32&quot;</span><span style="color:#ff0000"> Margin</span><span style="color:#0000ff">=&quot;0,-12&quot;/&gt;</span></li> <li>        <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">StackPanel</span><span style="color:#0000ff">&gt;</span></li> <li style="background: #f3f3f3">    <span style="color:#a31515"></span><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">StackPanel</span><span style="color:#0000ff">&gt;</span></li> <li><span style="color:#0000ff">&lt;/</span><span style="color:#a31515">ListBoxItem</span><span style="color:#0000ff">&gt;</span></li> </ol> </div> </div> </div>    <p>&#160;</p>    <p>This now means the tap event now more closely matches the visual area of the list item as shown in red below:</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7416.Test_ListItem_good_target_7A67EB56.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7416.Test_5F00_ListItem_5F00_good_5F00_target_5F00_7A67EB56.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="Test_ListItem_good_target" border="0" alt="Test_ListItem_good_target" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7416.Test_ListItem_good_target_thumb_2AAEC00D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7416.Test_5F00_ListItem_5F00_good_5F00_target_5F00_thumb_5F00_2AAEC00D.png" width="244" height="404" /></a>&#160; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7220.contact_sample_1E409CE4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7220.contact_5F00_sample_5F00_1E409CE4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="contact_sample" border="0" alt="contact_sample" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/5153.contact_sample_thumb_039400CB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/5153.contact_5F00_sample_5F00_thumb_5F00_039400CB.png" width="244" height="404" /></a></p>    <p>This can apply to other areas too. The image on the right is a sample contact from the People hub, again with red boxes to mark out the touch target area for each key/value pair. Here the tap action does not only apply to the contact detail, instead the touch target area extends to include the associated heading. </p>    <p>By carefully considering the best size, spacing and scope for the tap event, the application will feel more responsive and easier to use. </p>    <p>&#160;</p> </div>  <p><em>Written by</em> <a href="https://blogs.msdn.com/b/wpukcoe/archive/tags/fiona+bell/default.aspx">Fiona Bell</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Fast Application Switching and Acquired OS Resources</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/fast-application-switching-and-acquired-os-resources</link>
      <pubDate>Fri, 06 Jan 2012 01:49:01 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/01/06/fast-application-switching-and-acquired-os-resources/</guid>
      <description><![CDATA[Fast Application Switching (FAS) is a new feature of Windows Phone 7.5 and provides an improved...]]></description>
      <content:encoded><![CDATA[<p>Fast Application Switching (FAS) is a new feature of Windows Phone 7.5 and provides an improved experience when the user is switching between applications. The application is no longer terminated when the user navigates away from the application. Instead the application remains in memory and is not running at all, but its state and data are preserved. This is called the “dormant” state. </p>  <p>When an application enters the dormant state, the OS will take away certain system resources from the application. For instance, the camera resource is exclusive and it will be made available for other applications. But what happens when your application is reactivated? The OS will try to return the resources to your application wherever possible. The tricky bit is that some resource types will be returned to your application seamlessly and some resources will have to be reclaimed by the application itself. See list below.</p>  <table border="1" cellspacing="0" cellpadding="0"><tbody>     <tr>       <td valign="top" width="215">         <p><b>Resource</b></p>       </td>        <td valign="top" width="236">         <p><b>Work done by OS</b></p>       </td>        <td valign="top" width="370">         <p><b>Work to be done by reactivated application</b></p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>XNA Audio</p>       </td>        <td valign="top" width="236">         <p>Resumed</p>       </td>        <td valign="top" width="370">         <p>None. SoundEffect is resumed automatically.</p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>Sensors </p>       </td>        <td valign="top" width="236">         <p>Notifications resumed</p>       </td>        <td valign="top" width="370">         <p>None. Sensor notifications are resumed automatically.</p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>Networking</p>       </td>        <td valign="top" width="236">         <p>Completed with Cancellation</p>       </td>        <td valign="top" width="370">         <p>Re-issue the network request.</p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>Sockets</p>       </td>        <td valign="top" width="236">         <p>-</p>       </td>        <td valign="top" width="370">         <p>Socket has to connect again.</p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>MediaElement</p>       </td>        <td valign="top" width="236">         <p>-</p>       </td>        <td valign="top" width="370">         <p>Media will not resume. Set <i>Source</i> property and start <i>Play()</i>.</p>       </td>     </tr>      <tr>       <td valign="top" width="215">         <p>Camera </p>       </td>        <td valign="top" width="236">         <p>-</p>       </td>        <td valign="top" width="370">         <p>PhotoCamera/VideoCamera objects must be created again. Calling any method on the old object will throw ObjectDisposedException.</p>          <p>For <em>CameraCaptureTask</em> no action is required<em>, its</em> object is preserved. If desired, call <i>Show()</i> method to show camera application.</p>       </td>     </tr>   </tbody></table>  <p>I want to specifically call out networking, because almost all applications are connected nowadays and that’s where the first bugs can often be found when implementing fast application switching. </p>  <p>&#160;</p>  <h3>Networking</h3>  <p>For example, let's explore what happens to a WebClient during a fast application switch. We already know that after FAS, the application’s state is retained and objects remain instantiated. Similarly, the WebClient object and its event handlers remain wired up. The only trouble is that during FAS, our network calls will get cancelled. The good news is, this is easy to detect. After the application is reactivated, the WebClient will be notified about the network request cancellation. In particular, the WebClient’s “Completed” handler will be triggered with “Cancelled” flag set. To get your application going again, re-issue the WebClient request and that’s it, your application now supports fast application switching. </p>  <p>Note that the application has to re-issue only network requests made explicitly. Silverlight controls that use network behind the scenes will download the content correctly. For instance &lt;Image&gt; control pointing to an http source will seamlessly complete image download after fast application switching. </p>  <p>&#160;</p>  <h5>Detecting cancelled WebClient request</h5>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:df100a2c-619a-4628-a656-450b1e1fa206" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #ddd; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#2b91af">WebClient</span> client = <span style="color:#0000ff">new</span> <span style="color:#2b91af">WebClient</span>();</li> <li style="background: #f3f3f3">&nbsp;</li> <li>client.OpenReadCompleted += <span style="color:#0000ff">new</span> <span style="color:#2b91af">OpenReadCompletedEventHandler</span>(ClientOpenReadCompleted);</li> <li style="background: #f3f3f3"><span style="color:#2b91af">Uri</span> requestUri = <span style="color:#0000ff">new</span> <span style="color:#2b91af">Uri</span>(<span style="color:#a31515">&quot;https://www.contoso.com/somedata.dat&quot;</span>);</li> <li>client.OpenReadAsync(requestUri, requestUri);</li> <li style="background: #f3f3f3">...</li> <li>    </li> <li style="background: #f3f3f3">&nbsp;</li> <li><span style="color:#0000ff">void</span> ClientOpenReadCompleted(<span style="color:#0000ff">object</span> sender, <span style="color:#2b91af">OpenReadCompletedEventArgs</span> e)</li> <li style="background: #f3f3f3">{</li> <li>    <span style="color:#0000ff">if</span> (e.Cancelled)</li> <li style="background: #f3f3f3">    {</li> <li>        <span style="color:#008000">// Web request has been cancelled</span></li> <li style="background: #f3f3f3">        <span style="color:#008000">// e.UserState contains cancelled request Uri, which we have passed as userToken in OpenReadAsync method</span></li> <li>    }</li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div>  <h5>Detecting cancelled HttpWebRequest</h5>  <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:730239e9-95b7-45db-8800-2f1beb2dbce9" class="wlWriterEditableSmartContent"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background: #ddd; overflow: auto"> <ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"> <li><span style="color:#2b91af">HttpWebRequest</span> request = <span style="color:#2b91af">WebRequest</span>.CreateHttp(<span style="color:#a31515">&quot;https://www.contoso.com/somedata.dat&quot;</span>);</li> <li style="background: #f3f3f3">request.BeginGetResponse(<span style="color:#0000ff">new</span> <span style="color:#2b91af">AsyncCallback</span>(<span style="color:#0000ff">this</span>.httpWebRequestCompleted), request);</li> <li>...</li> <li style="background: #f3f3f3">&nbsp;</li> <li><span style="color:#0000ff">private</span> <span style="color:#0000ff">void</span> httpWebRequestCompleted(<span style="color:#2b91af">IAsyncResult</span> asyncResult)</li> <li style="background: #f3f3f3">{</li> <li>    <span style="color:#2b91af">HttpWebRequest</span> request = (<span style="color:#2b91af">HttpWebRequest</span>)asyncResult.AsyncState;</li> <li style="background: #f3f3f3">    <span style="color:#2b91af">HttpWebResponse</span> response;</li> <li>&nbsp;</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">try</span></li> <li>    {</li> <li style="background: #f3f3f3">        response = (<span style="color:#2b91af">HttpWebResponse</span>)request.EndGetResponse(asyncResult);</li> <li>    }</li> <li style="background: #f3f3f3">    <span style="color:#0000ff">catch</span> (<span style="color:#2b91af">WebException</span> ex)</li> <li>    {</li> <li style="background: #f3f3f3">        <span style="color:#0000ff">if</span> (ex.Status == <span style="color:#2b91af">WebExceptionStatus</span>.RequestCanceled)</li> <li>        {</li> <li style="background: #f3f3f3">            <span style="color:#008000">// HttpWebRequest has been cancelled</span></li> <li>        }</li> <li style="background: #f3f3f3">    }</li> <li>}</li> </ol> </div> </div> </div>  <p>&#160;</p>  <h3>Tips for implementing and testing fast app switching with networking:</h3>  <ul>   <li>Distinguish between no network availability and a cancelled network request due to fast app switch. Quite often applications incorrectly show error messages that the network is not available; instead the applications should re-issue the network request. </li>    <li>Do not show any popups or MessageBoxes, fast application switching is not an error state. </li>    <li>In cases where an action is triggered by a user and the application is unable to complete the user’s request, inform the user with an error message. For instance, the user is sending a message and the device moves to an area without network coverage. Please do inform the user that the transaction couldn’t be completed. (The reason for failure is no network coverage, not fast app switching) </li>    <li>On the contrary, upon successful message delivery, no confirmation would be shown to user. It is expected that all actions will complete successfully. </li> </ul>  <p>&#160;</p>  <h3>Example step-by-step FAS testcase</h3>  <p>Imagine phone application accessing an online store. User can browse products using his Windows Phone 7 application. A FAS testcase can go like this:&#160; </p>  <ol>   <li>Tap on Electronics section of the online store </li>    <li>As soon as “Loading…” starts, press the Start button on Windows Phone </li>    <li>Wait a second and press hardware back button to return to the application </li> </ol>  <p>Commonly observed bug:    <br />No results found or the application throws an exception</p>  <p>Expected result:    <br />List of products in electronics section is loaded when user returns to the application </p>  <p>&#160; </p>  <h3>Resources</h3>  <p><a href="https://channel9.msdn.com/events/MIX/MIX11/DVC09">Get Ready for Fast Application Switching in Windows Phone</a></p>  <p>&#160;</p>  <p><em>Written by</em>&#160; <a href="https://blogs.msdn.com/wpukcoe/archive/tags/Petr+Sedlacek/default.aspx">Petr Sedlacek</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Before you press send…</title>
      <link>https://docs.microsoft.com/archive/blogs/wpukcoe/before-you-press-send</link>
      <pubDate>Fri, 06 Jan 2012 01:34:44 GMT</pubDate>
      <dc:creator><![CDATA[Windows Phone UK Centre of Excellence]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/wpukcoe/2012/01/06/before-you-press-send/</guid>
      <description><![CDATA[As you can imagine, in the design team in Depth Partner Support we review hundreds of app designs...]]></description>
      <content:encoded><![CDATA[<p>As you can imagine, in the design team in Depth Partner Support we review hundreds of app designs every year, from all over the world, and from all kinds of different industries.</p>  <p>Aside from knowing our RenRens and Immowelts from our Magic Seaweeds and Univisions, we’ve also noticed some common issues that many partners fall foul of when they submit their designs to us for review.</p>  <p>The good news is they’re easy to fix.</p>  <p>So here are the top three issues we see at design review. Please have a look through these and check your apps to make sure they don’t suffer from these design no-nos before you send your docs on for review.</p>  <h3>Alignment and spacing</h3>  <p>This is an easy one. Everyone can tell if something isn’t properly aligned. In fact, if you’re not sure, you can do something as simple as attaching a sticky note to your monitor or mobile screen and see if everything lines up. As a general rule, everything in Windows Phone should be left aligned.</p>  <p>For those of you who prefer some more concrete guidance, the default page margins we suggest are 24 pixels from the left and right of the page. List items should be spaced 12 pixels apart, both horizontally and vertically. You should space controls either 12 or 24 pixels apart (or a multiple thereof). Use whichever looks best.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/8662.clip_image002_1FDCD10A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/8662.clip_5F00_image002_5F00_1FDCD10A.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/0245.clip_image002_thumb_3EB344E8.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/0245.clip_5F00_image002_5F00_thumb_5F00_3EB344E8.jpg" width="138" height="236" /></a> <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/3365.clip_image003_16A095C9.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/3365.clip_5F00_image003_5F00_16A095C9.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image003" border="0" alt="clip_image003" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/4848.clip_image003_thumb_1C7B3962.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/4848.clip_5F00_image003_5F00_thumb_5F00_1C7B3962.jpg" width="135" height="236" /></a></p>  <p>You can download Photoshop templates with the grid on them from <a href="https://go.microsoft.com/fwlink/?LinkId=196225">https://go.microsoft.com/fwlink/?LinkId=196225</a></p>  <h3>Back, close, cancel buttons</h3>  <p>As every Windows Phone ships with a handy hardware back button, you don’t need to create your own just to take up space on the screen. Plus, why bother with all the hassle of managing the back stack yourself?</p>  <p>People will use the back button:</p>  <p>· To navigate backwards</p>  <p>· To dismiss a dialog</p>  <p>· To cancel</p>  <p>So if you’ve got buttons on the UI that perform those functions, you might as well scoop them out!</p>  <p>There’s an exception to cancelling a process though, and I use the word process carefully. In this context I mean a discrete process that has a very obvious beginning and end, such as the checkout process of a shopping experience. You’ve tapped the checkout button, entered a shipping address, pressed next, entered a billing address, pressed next, entered payment details, and pressed confirm. The process has completed.</p>  <p>Normally you’d use the back button to navigate within this process. But say you were at the payment details screen and wanted to cancel the process to go back and add another product to your basket. Rather than making the user press back a bunch of times, we would recommend they use a cancel button which cancels the checkout process and drops them back at the basket. The whole checkout process would then need to be removed from the backstack. If this is something you want to do, then the cancel button should not be visible on the first page of the process (because the user can just as quickly tap the back button), but should appear on subsequent pages.</p>  <h3>Mixing metaphors</h3>  <p>If you see this button, what do you expect it to do?</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/4846.clip_image005_2255DCFB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/4846.clip_5F00_image005_5F00_2255DCFB.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image005" border="0" alt="clip_image005" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/8662.clip_image005_thumb_[8708.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/8662.clip_5F00_image005_5F00_thumb_5F00_5B008708.png" width="26" height="26" /></a></p>  <p>The chances are you said ‘play’. That’s a reasonable assumption. Wherever you see this icon in Windows Phone, it always means play and tapping it always plays media. Effectively, you’re used to this being a metaphor for playing media. If you saw that icon and tapping it didn’t play media, it would be confusing, right?</p>  <p>We often see this being used to mean ‘next’. In Windows Phone, we use this icon for next:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/6683.clip_image006_289CB389.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/6683.clip_5F00_image006_5F00_289CB389.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image006" border="0" alt="clip_image006" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/49/47/metablogapi/7563.clip_image006_thumb_484B8D51.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-49-47-metablogapi/7563.clip_5F00_image006_5F00_thumb_5F00_484B8D51.png" width="26" height="26" /></a></p>  <p>Both of these icons have shipped with the Silverlight Toolkit for Windows Phone (which can be downloaded here: <a href="https://silverlight.codeplex.com">https://silverlight.codeplex.com</a>) and can be found on your hard disk here: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.x\Icons on 64bit Windows, or C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Icons on 32bit Windows.</p>  <p>We’ve seen a load of apps that mix up what the icons mean just because it’s easier to reuse an existing icon than it is to create one appropriate for the use case. Please don’t do this. There are plenty of resources online, and using a more accurate icon will make for a much nicer experience, and your users will thank you for that.</p>  <p>&#160;</p>  <p><em>Written by</em> <a href="https://blogs.msdn.com/wpukcoe/archive/tags/Dave+Crawford/default.aspx">Dave Crawford</a></p>]]></content:encoded>
    </item>
  </channel>
</rss>