Android to Windows Phone 8 Part 3: Exploring the Windows Phone Project

April 11, 2013

 

Over the past several weeks I’ve been working on some content I’m excited to finally share with you through a series of blog posts. This series will introduce you to Windows Phone 8 development from an Android developer’s perspective. Through the course of the series you’ll create your first app. It won’t be anything pretty, but you’ll learn the ins and outs of the development environment, how to create a simple user interface, and how to perform navigation. Along the way you’ll see some Android Hints that will help make it easier for you to transition your existing skills to the Windows Phone platform. You’ll also see some Visual Studio Tips to make you more productive in your development environment. Good luck!

In the last lesson you created your first Windows Phone project. In this lesson you’ll spend some time exploring the project and learning about some key files and directories.

WMAppManifest.xml


This is the application’s manifest. It is an XML document that contains details about the app, such as the App ID and the capabilities the app uses.

ANDROID HINT

WMAppManifest.xmal is similar to the AndroidManifest.xml file used by Android applications.

 

Here is some additional information about the manifest:

  • When you submit your apps to the Windows Phone Store, info from the manifest file is used in the certification process, to filter your app correctly in the Store, and to deploy and run your app on the device.
  • The info from the manifest file is stored as metadata in the app database.

If you double-click the manifest in the solution explorer you’ll get a UI you can use to edit the various properties of the manifest. For this app we’ll leave everything as is.

ANDROID HINT

In the generic Android app example I mentioned earlier, you set the default activity for the app in AndroidManifest.xml. Typically it looks something like this:

If you open up WMAppManifest.xml you’ll see an option for Navigation Page this is where you set the default page for the app to open when it starts.

 

MainPage.xaml and MainPage.xaml.cs


As mentioned in the last lesson XAML (eXtensible Application Markup Language) is the declarative language used to create the UI for Windows Phone applications. MainPage.xaml is the default page for your application. This is where you’ll create your simple UI (in the next lesson). MainPage.xaml.cs is the associated C# code that goes along with your UI.

VISUAL STUDIO TIP

The *.xaml.cs file that is associated with a *.xaml file is called the code-behind file.

 

ANDROID HINT

The relationship between *.xaml and *.xaml.cs files is similar to the relationship between layouts and activities in Android development. When you create a generic Android app, you’ll get an activity_main.xml file in the res > layout
directory. This is where you define the UI for your Android app. You also get a MainActivity.java file in your src directory. This is where you write the code that goes along with the UI. In our app MainPage.xaml corresponds to activity_main.xml, and MainPage.xaml.cs corresponds to MainActivity.java

 

App.xaml and App.xaml.cs


App.xaml can be used to store information about application wide resources. By default a reference is added to a file used to store localized string values.

App.xaml.cs provides application-specific behavior to supplement the default application class. This is also where you can tie into the following events of the application lifecycle:

  • Launching – when the application is initially launched.
  • Activated – when the application is brought to the foreground after being in the background.
  • Deactivated – when the application is sent to the background due to a system event (i.e. phone call).
  • Closing – when the user presses the hardware Back button.

ANDROID HINT

The following table maps the appropriate Android method to its Windows Phone event counterpart:

Android Method

Windows Phone Event

onCreate()

Launching

onStart()

Launching

onResume()

Launching or Activated

onPause()

Deactivated

onStop()

Closing

onDestroy()

Closing

 

The Windows Phone application lifecycle will be covered in depth in another installment of this series.

Assets Directory

The Assets directory contains default artwork used by the application.

ANDROID HINT

The items contained in the Assets directory are similar to those found in the res/drawable-* directories of your Android projects.

 

Resources and LocalizedStrings.cs

The Resources directory contains resources used across the application. By default it contains one file, AppResources.resx. This file is where you store strings displayed in the UI for localization.

ANDROID HINT

AppResources.resx is similar to the res/values/strings.xml file used in Android projects.

 

The LocalizedStrings.cs file wraps access to the AppResources.resx file and gives your app programmatic access to the string resources it contains.

As you can see, Visual Studio gives you a lot for free so you can get started on your app. You should continue to explore your project set up as well as the files and directories that get created with the of the other project templates as Visual Studio does a lot of heavy lifting for you.

In the next lesson you’ll learn how to run your application.

Previous Posts in this Series

  • Setting up the Development Environment
  • Creating Your First Windows Phone Project

Additional Resources