The refresh of the WP7.1 SDK includes a second emulator running on the low end version of Windows Phone. With this developers can now test if their applications will keep running on the cheaper devices. If not, the user will get an error when trying to install your application stating that it won’t run on their low-end device. Users with a mid –or high-end device can keep using your app without any problems.
This is in fact the same emulator but running on a different image. After installing the update you won’t be able to launch the emulator from the Windows start menu anymore, to fix this add either –256 or –512 to the shortcut depending on what image you want to load in the emulator.
With that, let’s dive into some code and figure out what we can do on the low-end device.
I’ve created a demo project that on launch checks for the available amount of memory using a Device Extended Property from the new SDK called ApplicationWorkingSetLimit. I’ve poured this into a method that sets a private boolean to true if it’s a low-end device
<p>Note that the ApplicationWorkingSetLimit is a hardcoded string, so be very careful of typos. The 94371840 is the maximum amount of bytes my application can use on a low-end device.</p> <p>Another limitation of Windows Phone Tango is that it currently does not support background agents and that includes both periodic tasks as well as resource intensive tasks. When you try to add a background agent on a low-end device you get this:</p> <p></p> <p>That’s not a very clear error message is it? The inner exception doesn’t tell us much more. This will probably change once the new SDK is completely finished. So when you’re using background tasks in your application, please update your app with checks of the version. Don’t submit the update to the marketplace just yet because the current CTP version of the SDK doesn’t have a go-live license so it won’t pass marketplace certification.</p> <p>My example is an app that will set a random count to the application’s tile if it’s pinned to the start screen. In debug mode it will do this every 30 seconds. When you install it on the 256MB version of the emulator it won’t be able to register the agent, in fact it won’t even try because I have a build-in check for low memory devices.</p> <p>In my example I’ve used a boolean to store whether or not the device has low memory. This works because my app only has one page. In a real life application it would be better to store this into the IsolatedStorageSettings using this 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:4321094c-a20d-40b3-a6bb-185cfd3bd8e8" 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>private void CheckWP7Version()</li> <li style="background: #f3f3f3">{</li> <li> bool isLowEndDevice;</li> <li style="background: #f3f3f3"> </li> <li> //check if the device is low-end</li> <li style="background: #f3f3f3"> long result = (long)DeviceExtendedProperties.GetValue("ApplicationWorkingSetLimit");</li> <li> </li> <li style="background: #f3f3f3"> if (result < 94371840)</li> <li> {</li> <li style="background: #f3f3f3"> isLowEndDevice = true;</li> <li> }</li> <li style="background: #f3f3f3"> else</li> <li> {</li> <li style="background: #f3f3f3"> isLowEndDevice = false;</li> <li> }</li> <li style="background: #f3f3f3"> </li> <li> if (IsolatedStorageSettings.ApplicationSettings.Contains("IsLowEndDevice"))</li> <li style="background: #f3f3f3"> {</li> <li> IsolatedStorageSettings.ApplicationSettings["IsLowEndDevice"] = isLowEndDevice;</li> <li style="background: #f3f3f3"> }</li> <li> else</li> <li style="background: #f3f3f3"> {</li> <li> IsolatedStorageSettings.ApplicationSettings.Add("IsLowEndDevice", isLowEndDevice);</li> <li style="background: #f3f3f3"> }</li> <li> </li> <li style="background: #f3f3f3">}</li> </ol> </div> </div> </div> <p>And load the value anywhere in your application again like this</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:c607b1e5-a2a2-4eb9-9575-1e6c4b4a3a2b" 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 2em; padding: 0 0 0 5px;"> <li>var isLowEndDevice = IsolatedStorageSettings.ApplicationSettings["IsLowEndDevice"];</li> </ol> </div> </div> </div> <p>If for some reason your application can’t run on low-end devices you can block those devices from downloading it. To do this you need to add some lines to the application’s manifest file, right below the capabilities.</p> <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:af74d60b-b526-4103-9786-b4e7e6a46c68" 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 2em; padding: 0 0 0 5px;"> <li><Requirements></li> <li style="background: #f3f3f3"> <Requirement Name="ID_REQ_MEMORY_90" /></li> <li></Requirements></li> </ol> </div> </div> </div> </p> <p>With this in place the low-end devices will get a message stating that their device is not suited to run your application.</p> <p>I hope I gave you a good overview about what to expect with the new low-end devices and that you can adjust your applications to support these devices. Don’t be too worried about the memory limitations on the new devices, Microsoft scanned all available applications and found only 5 that utilise too much memory, they’ve contacted the developers and are working together with them to overcome these problems.</p> <p>The solution of my example can be found here(SkyDrive link).</p>
This is an imported post. It was imported from my old blog using an automated tool and may contain formatting errors and/or broken images.
Leave a Comment