Archive for the ‘Technology’ Category

With such a long and promising title, this series of posts better be a good one – you’ll be the judge of it. However, the real reason for this long title is rather simple. All these “big” words simply represent different aspects of the execution model. There are a few things that you need to know if you want to maximize your user’s experience. This post explains the Windows Phone (WP) application execution model by taking you step-by-step through the different aspects of launching, running, and closing a Silverlight application. Note that for XNA games the terms and ideas remain the same with some minor implementation differences. In following posts we’ll cover deactivation, reactivation, and how launchers and choosers work with tombstoning.

With the latest Beta release of the Windows Phone developer tools, applications running on WP employ an updated execution model. Now, when your application is removed from the phone foreground (a different application occupies the phone foreground like incoming phone call, or the lock screen being activated), it is actually being terminated (more on this later). In earlier version of the WP tools, you could get into all kinds of strange scenarios if you went from one application to another. That is because in the previous version of the tools, the WP operating system didn’t terminate your application, it “parked” it. However that led to some issues regarding launching a new instance of your application vs. navigating back to the instance on the back stack. Adding to the confusion, the events and API were less than perfect. I guess that is one of the reasons we have technical previews—to test and fix such “issues.”

A Few Ground Rules

Just to make sure we are all on the same page, by now you probably already know that the WP operating system doesn’t allow any 3rd party applications to run in the background. To be more specific, there can be only one application running in the foreground at any given time, and if your application is not running in the foreground, it means that your application is NOT RUNNING. The main reasons for not allowing 3rd party applications to run in the background are to preserve battery life (see Push Notification post) and to ensure a responsive and consistent user experience.

All WP devices feature a hardware Back button. This button allows the user to navigate back in a given application and even between applications. This is a rather cool feature, mainly because unlike other phones, you can navigate from your application to the browser or to another application, and then press Back to seamlessly return to your application. This yields a much more consistent user experience across different applications, whether they are 3rd party applications or part of the phone’s built-in application suite. This also implies that WP operating system is maintaining a journal of you navigation actions to support the Back button functionality. This is also known as the back-stack.

The Basics – Launching, Running, and Closing Applications

It is time to jump into the Windows Phone execution model, and the best way to do this is to start looking at some code. Simply start a new Windows Phone application and look at the auto-generated code of a new WP Silverlight application template, and you will find four new methods in the App.xaml.cs file that are directly related to the execution model:

  • Application_Launching
  • Application_Activated
  • Application_Deactivated
  • Application_Closing

As a side note, all these events (the functions are the event handlers) are members of thePhoneApplicationService class in the Microsoft.Phone.Shell namespace.

I think the names of these methods are rather self-explanatory, but just to be on the safe side, let’s review them. We’ll address the Activated and Deactivated methods later; for now, let’s focus on the simple events: Launching and Closing. I’ve added a single line of code to each method:

// Step 1 - Util is helper class for logging
Util.Trace("***** in MainPage CTOR\t\t ( " + DateTime.Now.Ticks + " *****)");

Util is a simple helper class that we’ll use to help us with debugging. The text in each method changes according to the event but you get the idea. I log the time of each event in order to prove a point later when we talk about Activated and Deactivated events.

Running the application in its current state yields the expected result. Upon launching your application the “Launching” method is called. As expected, after that event, your application runs. Press the Back button (not the Windows button) and your application terminates and the “Closing” event is raised, as you can see in the following image (copy of the output window from Visual Studio).

image

As we said, by pressing the hardware Back button, the navigation model allows the user to “step back,” or navigate backwards through the application pages, and even across applications. However once you reach to the application’s first page (the first page, and its first instance) pressing the Back button raises the Closingevent and terminates your application. You can see that from the above image, where it clearly states that the “program” exited. If you are following this post while coding in Visual Studio you will also note that the emulator exits your application and returns to the Start window.

Understanding Activated and Deactivated Events and Tombstone

So far so good, I mean there is nothing new here. However, let’s try the following trick. From Visual Studio, start your application in debug mode (so we can see the traces). As expected, your application starts and you should see the Application Launching trace in the log. Now, instead of pressing the Back button (which if you do, will terminate your application), press the Windows button (the middle button).

You should notice the following:

  1. The emulator returned to the Start screen and your application doesn’t occupy the phone’s foreground, which means it is no longer running!
  2. The debugging session in Visual Studio was terminated. This means that Visual Studio is not debugging your application, which makes sense since the application is no longer running.

Note: At the end, your application gets terminated. That is super easy to see in the Visual Studio Output window, as the last line in the Output windows states, “The program ‘[220921918] taskhost.exe: Managed’has exited with code 0 (0x0).” No worries, this is by design. However, unlike our previous example, this time the event that followed the Launching event is “Deactivated,” and NOT Closing. But in both cases your application gets terminated (at the end). So what is going here? What is the difference between Closing and Deactivated and more important, why?

image

  • Application Closing is simply the outcome of the user pressing the hardware Back button enough times to navigate backwards through the pages of your application, past the application’s first page. Currently, this is the ONLY way for a user to exit your application. Once your application is closed, its process is terminated, and the operating system removes any trace of that application from its memory (RAM).
  • Application Deactivated occurs when a different application takes control of the foreground – for example, an incoming phone call, launching a chooser, or the user pressing the Windows button. In both cases, your application will be deactivated (not closed). Before we step into the subtleties of the Deactivated event, let’s make sure we all understand that upon Deactivation, your application gets terminated (at the end). It’s that simple; your code can’t run in the background, therefore your application gets terminated. However, unlike an application that is closed, a deactivated application gets tombstoned. Don’t get confused, a tombstoned application’s process still gets terminated. But unlike a closed application, where the WP operating system removes any trace of the application, when an application is deactivated, the WP operating system stores a record (a tombstone) of the application’s state. Basically, the WP operating system keeps a tombstone of the application that becomes part of the phone’s application back-stack, which is a journal that enables the use of the hardware Back button to enhance navigation functionality.

There are several ways in which applications can become tombstoned. An application will be tombstoned and deactivated if:

  • The user presses the Windows button (as you just did)
  • The device timeout causes the lock screen to be engaged (again, a different application takes control of the foreground)
  • The user invokes a Launcher or a Chooser – which we will cover later

In any of these cases, the running application will be deactivated, the Deactivated event is raised, and your application gets terminated shortly afterwards.

At this point in the application life cycle (while your application is tombstoned), a few things can happen. The user might return to a tombstoned application. This can happen if the user completes the chooser or launcher activity and returns to the application, or if the user presses the Back button enough times to return to the tombstoned application. Regardless of how users return to the tombstone application, the application will be reactivated (raising the Activated event) and magically show the last page viewed by the user before the deactivation.

You don’t believe me, let’s try it together. I’ve added a second page to the basic WP Silverlight application, and added a trace to both constructor pages. Next, I added a button to the first page that navigates to the second page.

In Visual Studio, start debugging your application and click the button to navigate to the second page. From the second page, press the Windows button. As expected, your application is deactivated and then terminated, as you can see from the following screen capture of the Visual Studio Output window.

image

Note the sequence of the trace (and the corresponding time-code). First your application launches, then the main page constructor is called, and after pressing the button on page one, the application navigates to the second page (DetailsPage), after which you press the Windows button raising the Deactivated event, which indicates that your application is tombstoned.

In the next post you’ll learn about returning to a tombstoned application and managing your state between tombstoning.

You can download the code for the code samples.

Windows Phone 7 Training Kit for Developers includes a full lab dedicated to the Windows Phone Application Lifecycle.

MSDN documentation includes a topic – Execution Model Overview for Windows Phone

Source: The Windows Phone Developer Blog

Advertisements

As you know, Windows Phone 7 devices support theming: they allow you to pick Dark or Light backgrounds and choose an accent color. It’s really easy to configure your application to use predefined styles like “Disabled” or “Active” – they react to theme changing and you always get a well-colored UI. The real question is how to use different images for each theme. There is no standard way of detecting a theme and distinguishing resources based on it. I’ve surfed the web and found a solution proposed by Derik Whittaker – it detects theme by checking the color of the background. But what to do with obtained theme? The variants I’ve found at MSDN forums was not nice enough so I had to write something myself. My solution is resources-based and allows you to distinguish UIs for each theme just by adding two dictionary entries with same key. So let’s start.

Here we define ApplicationTheme enum that will distinguish our themes:

Enum

Then we implement a solution by Derik Whittaker:

Whittaker

It’s rather simple: it takes current PhoneForegroundColor property from application resources and determines theme based on it.

Now we’re going to organize an access to theme-specific resources via the ThemeResources class:

ThemeResources

Right after first call to ThemeResources they will initialize ResourceManager based on ApplicationTheme. Files used for resource storage should be it the same namespace with ThemeResources file:
Files

These .resx files should be named appropriately for each valid ApplicationTheme enumeration value: Dark or Light.

That’s it! All is left is using our ThemeResources class. Let’s define a property with some text and then bind to it:

Property

Binding

This code will automatically determine what theme is enabled and will pick appropriate application title:

DarkLight

You can easily store not only application titles but also for image URLs (what this solution was really intended for). You may need to show a white image in Dark theme and black image in Light theme – use this solution to achieve this cleanly and easily.

Download sources from our Deviation Alliance Codeplex project.

Source: Deviation Alliance

Shortly after Yahoo launched its HTML5-based version of Yahoo Mail for iPad, Google has refreshed its version of Gmail for Apple’s popular tablet.

The update boils down to one feature, albeit an interesting one: the app now has a new “stacked card” interface for selecting and managing multiple conversations. Before this latest update, one had to manage selected conversations and currently open conversations with two separate (and similar) toolbars. Now, when you select multiple conversations, you’ll see them “stacked” on the right, and you can archive, trash or move them easily.

The new version of Gmail for iPad also features some sleek new CSS3 transitions, described in detail on Google’s code blog.

To try the new Gmail for iPad, open gmail.com in your iPad’s Safari web browser.

Below are two applications that do exactly the same thing, but one was a whole lot easier to create. Can you guess which one? As an end-user it’s impossible to tell but in this article we examine how similar and yet different the development experience is for each of the apps. One of the apps below (on the right) is coded inAndroid 2.2 (aka Froyo) and the other using Windows Phone 7 Beta SDK. I tried to keep both projects as simple as possible so that people can understand the fundamentals over the design.

Download Sample Project Code Files

To get started with Windows Phone 7: http://developer.windowsphone.com, download the necessary software and Windows Phone SDK from the link listed. These tools will be used to run the examples; namely Visual Studio 2010, Windows Phone 7 Beta SDK, and Microsoft Expression Blend (optional).

The sample provided is just a small application which can convert between Fahrenheit, Celsius, and Kelvin.

I want to begin by addressing the similarities between the Android and Windows Phone 7 platforms. Both platforms have adopted the approach to separate design from logic. In Android, developers are used to coding “Layouts” and in Windows Phone 7 the equivalent is called a “Page”. Both of these layout methodologies involve creating an XML based layout. WP7 uses a mutated version of XML called XAML (pronounced “Zamel”). In both the Layouts and the Pages of each platform there is code behind that connects to your layout.

main.xml (Android)
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget0"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
</AbsoluteLayout>
MainPage.xaml (WP7)
<phone:PhoneApplicationPage
    x:Class="TemperatureConverterSample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    shell:SystemTray.IsVisible="True">
    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
         
    </Grid>
</phone:PhoneApplicationPage>

The equivalent of an Android “Activity” would be best described by the C# class which is connected to your XAML page and extends Microsoft.Phone.Controls.PhoneApplicationPage.

Android Activity
public class MainActivity extends Activity {
        // Code behind goes here…
 }
WP7 Page
 public partial class MainPage : PhoneApplicationPage
 {
       // Code behind goes here…
 }

Okay so its clear that there are similarities in terms of the core fundamentals of each platform, not to mention Java and C# are like brothers from another mother.

Phone Controls

The Windows Phone 7 equivalent to Android Widgets are called Controls and are a part of the System.Windows.Controls namespace. These “UIElements” are used in much of the same way that Widgets are. For instance the “Convert” button used in the apps is defined as such in  Android and WP7 respectively:

Android
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:layout_x="106px"
android:layout_y="292px"
>
</Button>
WP7
 <Button Content="Convert" Height="83" HorizontalAlignment="Left" Margin="24,487,0,0" Name="calculateButton" VerticalAlignment="Top" Width="400" Click="calculateButton_Click" />

Listeners vs Events

To handle a Button click in Windows Phone 7 we would use a Click Event rather than an Android Event Listener.

Android Click Listener
this.closeButton = (Button)this.findViewById(R.id.calculateButton);
        this.closeButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
     }
}
WP7 Button Click Event
Xaml Event name specified
<Button Content="Convert" Height="83" HorizontalAlignment="Left" Margin="24,487,0,0" Name="calculateButton" VerticalAlignment="Top" Width="400" Click="calculateButton_Click" />
C# Event Method Definition
private void calculateButton_Click(object sender, RoutedEventArgs e) {
      // Code for button
}

The Layout of your Apps

Similar to Androids Layout Views, Windows Phone 7 supplies developers a set of objects to layout Controls. There are Grids, StackPanels, Canvas and so on which have various methodologies of displaying UIElements. You can write your own as well. The reference for all of these such layouts can be found on the Microsoft MSDN reference pages.

hello-linearlayout

The equivalent for a LinearLayout in Android would be the StackPanel in WP7.

Differences Between the Platforms

So far we have yet to discuss the differences between the platforms. The main difference between Android and WP7 is in the development tools. In terms of coding, Android may be built on Java which is an open source platform with a ton of available code but C# is a very strong programming language with many nice features of its own. For instance, data binding to Controls in Silverlight is a really nice standard feature. After coding your app you can style it up in Microsoft Expression Blend 4. User interface designs can be “templated” which provides a CSS stylesheet type logic for programming your user interfaces on the phone.

Behaviors in Microsoft Expression Blend 4 allow people to build games use physics like a physics engine without even doing any code. Any Control in Silverlight can have a custom style. For instance, you can have a button which fades out or changes to all the colors of the rainbow when clicked. Whatever your imagination can think up is possible in an easy and highly customizable fashion.

Conclusion

The Android Platform and Windows Phone 7 share a lot of commonalities. It will take a while to get used to migrating from Android + Eclipse to Windows Phone 7 + Microsoft Visual Studio + Expression Blend but in the end it is a much smoother development experience. The tools which Microsoft provide add a wealth of ease to the lives of us developers.

Source: The Dirty Developer

Windows® Phone 7 lets you make the most of every moment by connecting and playing with friends wherever you are, using your Xbox LIVE® avatar and gamer profile to keep track of scores and wins.

Games on the go
Xbox LIVE, the award-winning online gaming and entertainment service for Xbox 360, is coming exclusively to a Windows Phone 7 near you this holiday. Whether you’re waiting for the bus, enjoying time out of town or just relaxing on the couch, the phone designed to keep your life in motion puts Xbox LIVE and mobile gaming in your pocket.

Always be in the game with the only phone
that lets you take Xbox LIVE mobile.

Xbox LIVE on Windows Phone 7

Connected and Accessible
Xbox LIVE on Windows Phone 7 unlocks a world of games, friends and fun for Windows Phone 7 users around the world. The Games hub brings together many popular Xbox LIVE gaming and community features:

  • Be omnipotent. View, access and launch your full game library from one easy-to-navigate hub.
  • Get mad props. Earn, view and track Achievements, view Xbox LIVE leaderboards and build your Gamerscore every time you play an Xbox LIVE title.
  • Release your inner Mini Me.Connect to your Xbox LIVE profile and Avatar, or easily create a new one right from the phone.
  • Get tricky. Access Spotlight feeds, including the latest game titles, breaking news from Xbox LIVE, game tips and tricks, and more.
  • Play before you pay. Easily find, try and buy the games you want, either in the Marketplace or Games hub.
  • Flaunt your skills. Invite, connect and play against friends on other Windows Phone 7 phones or PCs with turn-based (asynchronous) multiplayer gaming.

Windows Phone 7 featuring Xbox LIVE lets you connect and play games with your friends. Use your Xbox LIVE profile to access your avatar, gamerscore, and achievements. Share scores and earn recognition for your accomplishments across the phone, web, and Xbox. You can even earn achievements on Windows Phone that add to your Xbox LIVE gamerscore.

Windows Phone 7 Marks a New Era in Mobile Gaming

At gamescom 2010, Microsoft premiered the first wave of Xbox LIVE games launching on Windows Phone 7 this holiday. With even more games and applications to come, Windows Phone 7 is putting the power of Xbox LIVE into the palm of your hand—from Xbox LIVE Avatars to staying connected with friends, Xbox LIVE is now at your fingertips, anytime, anywhere. Read more …

Games Lineup
The first wave of games announced in the launch portfolio of Xbox LIVE games on Windows Phone 7 has something for every mobile gamer:

  • 3D Brick Breaker Revolution (Digital Chocolate)
  • Age of Zombies (Halfbrick)
  • Armor Valley (Protégé Games)
  • Asphalt 5 (Gameloft)
  • Assassins Creed (Gameloft)
  • Bejeweled™ LIVE (PopCap)
  • Bloons TD (Digital Goldfish)
  • Brain Challenge (Gameloft)
  • Bubble Town 2 (i-Play)
  • Butterfly ( Press Start Studio)
  • CarneyVale Showtime (MGS)
  • Crackdown 2: Project Sunburst (MGS)
  • De Blob Revolution (THQ)
  • Deal or No Deal 2010 (i-Play)
  • Earthworm Jim (Gameloft)
  • Fast & Furious 7 (i-Play)
  • Fight Game Rivals (Rough Cookie)
  • Finger Physics (Mobliss Inc.)
  • Flight Control (Namco Bandai)
  • Flowerz (Carbonated Games)
  • Frogger (Konami Digital Entertainment)
  • Fruit Ninja (Halfbrick)
  • Game Chest-Board (MGS)
  • Game Chest-Card (MGS)
  • Game Chest-Logic (MGS)
  • Game Chest-Solitaire (MGS)
  • GeoDefense (Critical Thought)
  • Ghostscape (Psionic)
  • Glow Artisan (Powerhead Games)
  • Glyder 2 (Glu Mobile)
  • Guitar Hero 5 (Glu Mobile)
  • Halo Waypoint (MGS)
  • Hexic Rush (Carbonated Games)
  • I Dig It (InMotion)
  • iBlast Moki (Godzilab)
  • ilomilo (MGS)
  • Implode XL (IUGO)
  • Iquarium (Infinite Dreams)
  • Jet Car Stunts (True Axis)
  • Let’s Golf 2 (Gameloft)
  • Little Wheel (One click dog)
  • Loondon (Flip N Tale)
  • Max and the Magic Marker (PressPlay)
  • Mini Squadron (Supermono Limited)
  • More Brain Exercise (Namco Bandai)
  • O.M.G. (Arkedo)
  • Puzzle Quest 2 (Namco Bandai)
  • Real Soccer 2 (Gameloft)
  • The Revenants (Chaotic Moon)
  • Rise of Glory (Revo Solutions)
  • Rocket Riot (Codeglue)
  • Splinter Cell Conviction (Gameloft)
  • Star Wars: Battle for Hoth (THQ)
  • Star Wars: Cantina (THQ)
  • The Harvest (MGS)
  • The Oregon Trail (Gameloft)
  • Tower Bloxx NY (Digital Chocolate)
  • Twin Blades (Press Start Studio)
  • UNO (Gameloft)
  • Women’s Murder Club: Death in Scarlet (i-Play)
  • Zombie Attack! (IUGO)
  • Zombies!!!! (Babaroga)

Microsoft_game_studios_logo

Just ahead of Gamescom and their reported multiple gaming announcements, Microsoft is evidently launching Mobile Gaming Studio, under the umbrella of the larger Microsoft Game Studios.

The information comes from, where else, a job posting, which details

Microsoft Games Studios is establishing a new Studio – MGS Mobile Gaming – focused on bringing games and entertainment to the mobile life that people lead. Our vision is to deliver games and entertainment so good that people will want them always with them, on a service that makes them social, connected and relevant anywhere their life goes. The Mobile Gaming team is building industry leading products that showcase our Windows Phone platform as well as emerging mobile platforms, and will help realize Microsoft’s connected entertainment vision. The Mobile Gaming studio will be the hub for MGS franchises and titles on mobile devices and a center of excellence for mobile games.

That bit about "…emerging mobile platforms" sounds a lot like tablet aspirations, no? It’s not a stretch to think that Microsoft envisions you playing games on your Xbox, PC, phone and someday your tablet–we’re down with that. We’re also hoping that "MGS franchises" bit refers to some Halo/Gears of War mobile action.

The only shocker here is that Microsoft is doing this now, as opposed to say last February? We’re going to go on a limb here and say (hope?) that Microsoft already has a mobile-gaming team in place, cranking out some titles for the Fall.

Well, here it is folks, just in time for Monday morning–the HTC Schubert, which is expected to be one of the first GSM phones featuring Windows Phone 7 to hit the market.

Part of the device’s sexy looks comes form the aluminum unibody design, much like the Android-based HTC Legend (see more on that here).

Unfortunately while we have pictures, we don’t have any specifications for the device, though you can bet on at least a 1GHz processor and ample RAM like all WP7 Chassis 1 devices.

Watch the full video after the break and here are some screenshots below. Thoughts? Lets us know in comments.

Source: 247 Windows phone via Solo Palmari