Nokia Lumia 800 as my new emulator for Windows Phone development.
Exiting a Windows Phone Application Programatically
This is just a helpful tip for those who do Windows Phone development. I had issues on trying to figure out what the best way was to exit my app from the app’s main root page. For a while I just threw an exception such as this:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
throw new Exception(“Exit Main”);
}
It irked me to do this, but it worked and passed Marketplace certification. Well, I was needing to perform some code on the App.xaml.cs level when exiting my app:
private void Application_Closing(object sender, ClosingEventArgs e)
{
// Do stuff here
}
Well, this code was never called due to the exception being thrown from my main page when the back button was pressed. So, I dug in a bit to the NavigationService class and realized I could actually remove all back entries that were on the back stack. Joy! So, this is what I came up with for the OnBackKeyPress event:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
if (NavigationService.CanGoBack)
{
while (NavigationService.RemoveBackEntry() != null)
{
NavigationService.RemoveBackEntry();
}
}}
And voila! It worked. The app exited properly and the Application_Closing event was called from App.xaml.cs which allowed me to do some background processing of my app’s data.
Hope this can help any of you.
Snippets: String to enumerated values
Useful code I use to convert string values to its enumerated counter parts.
public static T StringToEnum<T>(string name)
{
return (T)Enum.Parse(typeof(T), name, false);
}
public static T NumToEnum<T>(int number)
{
return (T)Enum.ToObject(typeof(T), number);
}
Pretty cool. Lois Lane uses a Windows Phone on an episode of Smallville. Just saw this during lunch today. I had to record it. Although, I am sure I am the last to know of course.
Generic agents for Windows Phone 7 (overview)
I am learning about generic agents in Windows Phone 7. I thought I would share what type of agents are available for Windows Phone.
Generic agents enables you to run custom code at regular intervals in the background of an app. There is a 1:1 ratio of an app and a generic agent. Each app has only 1 agent.
Code that needs to be run in the background lives in an agent which is a separate library (.dll file that contains the code to run in the background) that is associated with the foreground app.
The OS installs, stores, and updates the agent and foreground app together. The background agent is created and registered in the foreground app.
There are two types of scheduled tasks. That is a periodic task, and a resource intensive task that we can create in our foreground app.
Period tasks runs agent code every 30 minutes for 15 seconds. Each time the task is run the associated code gets executed in the background.
Resource intensive tasks only runs if and when the phone is in a state that power, network and processing resources are readily available (night stand mode):
- connected to an external power instead of the battery
- wifi is available, instead of cellular
- the battery is at least 90% charged
- lock screen is on
- and there active phone call
The phone will run the task for up to 10 minutes. This will allow the phone to perform some extensive data syncing, uploading, downloading scenarios.
The background agent can be assigned as a periodic task, resource intensive task, or both (This will allow the phone to run tasks every 30 minutes for 15 seconds and when in night stand mode, when the above conditions are met, for 10 minutes)
I will post some sample code soon.
Working on some graphics for GoGetter. An alarm clock! Whoa!
Unofficial Klout app coming to Windows Phone. We're impressed. [Video]
Klout for Windows Phone. Finally.
I have two Windows Phones!
Windows Phone feeds
Here is a bundle of Windows Phone 7 feeds I made. It has the exact same feeds as the app “Windows Phone News” for the Windows Phone. Enjoy!




