📜 ⬆️ ⬇️

Development for Windows Phone 7 for Android developers

Developing applications for the Windows Phone 7 platform is similar to developing for the Android platform more than you might expect. In this article, Chris Bennett explores the similarities between the two platforms.

As well as mobile applications for the Android platform, applications for Windows Phone 7 are written in a managed language — Java for Android and C # for Windows Phone 7 — with accompanying libraries. Many of the differences between Java and C # are related to style. Two modern languages ​​have a common origin from C / C ++ languages ​​and have strong similarities with each other.

There are certainly differences between .NET / Windows Phone 7 and the Java / Android API, but since the languages ​​are similar, you can save most of the logic you created in an existing application when porting it to Windows Phone 7. In fact, you will see That start is very easy. For an example, you can see the Windows Phone 7 article for Java developers .

Platform Differences


Before delving into specific tools and processes for porting and / or creating applications for Windows Phone 7, let's begin with the terminology and technological differences between Windows Phone 7 and Android. The first big difference is that Windows Phone 7 applications are created as managed .NET assemblies written in C #. The platform supports two types of applications: Silverlight and XNA games.
Most applications for Windows Phone 7 are created using Silverlight, which provides a form-based way to interact with the user through standard controls, such as labels, text fields, lists, etc. The equivalent in Silverlight for Android Layout and its accompanying Activity is Page.
Another type of application supported by Windows Phone 7 is XNA, which allows developers to create 2D and 3D games. This is the equivalent of Android SurfaceView and GLSurfaceView for 2D and 3D, respectively. Unlike Android, which is focused on using OpenGL for games, XNA games use Direct3D, which makes it easier to port games from PC and Xbox 360 platforms.
')

Pages and Navigation


Silverlight Pages are created as XML files, as well as Android Layouts. The XAML (Extensible Application Markup Language) is used to describe the Page in the XML file. XAML is similar to Android Layout, but it has a wider range of capabilities. XAML allows developers to implement actions related to the Page, including animation, data binding, and more, which reduces the amount of code needed.
Android Layout is separated (decoupled) from the Activity used to perform actions. As a result, you are forced to write code in order to associate an Activity with the corresponding elements of the user interface (UI). C # code for a specific Page is already bound to UI elements and there is simply no need for that. The platform automatically creates the necessary “bindings” for objects and events for the Page and the user interface. This prevents the clutter that usually occurs in the OnCreate method of each task, where you create bindings to the UI and the various necessary handlers.
Another important difference between the platforms is navigation. In Android, you switch from one task to another, creating an Intent. The analogue in Windows Phone 7 is Navigation, which allows you to navigate between different Pages. As in Android Intent, you can transfer the data to the Page to which you are moving. Page in Windows Phone 7 has some properties similar to ASP.net Page. For example, QueryString is typically used to pass information to the next Page.

Convert Layouts to Pages


Before diving into the code, we need to look at the transformation of Android Layout XML to Windows Phone 7 XAML Pages. Of course, one of the advantages of free tools for Windows Phone 7 is the quality of the design tools available for XAML. The XAML designer included in Visual Studio 2010 is intended to be used primarily by developers to get the basic controls for the Page and start developing. Expression Blend is designed to create a professional design with a more advanced set of tools to improve the user interface. As in the case of the Android Layout, you can always resort to editing XAML directly in a text editor, since this is a regular XML file.
Windows Phone 7 Page provides layout and controls similar to Android Layout. The following table shows analogs for both platforms.

Markup Elements
Windows Phone 7Android
CanvasAbsoluteLayout
GridGridview
ScrollviewScrollview
StackpanelLinearlayout
As you can see, Windows Phone 7 provides the same features for creating markup. The following table lists the main controls.

Basic controls
Windows Phone 7Android
TextblockTextview
TextboxEdittext
ButtonButton
CheckboxCheckbox
RadiobuttonRadiobutton
ImageImageView
ProgressbarProgressbar
ListboxListview
MapMapView
WebbrowserWebview
Please note, Windows Phone 7 has one-to-one correspondences for basic markup and control elements. But for some of the specialized markup and control elements, there is no match. The reason for this lies in the rich capabilities of XAML, which makes it very easy to insert controls into each other. Thus, for example, you can add a list (ListBox) with checkboxes (CheckBoxes) next to each item without having to write any code. This means that you do not need all these complex bundled controls, they can be created and modified within your application.

Data storage


Data storage is a big part of the task when developing most mobile applications. In Windows Phone 7, the idea is to use cloud services as the primary means of storing data. At first glance, this may seem a bit strange to you, but if you create an application client for your site, it makes sense. If you are not going to follow this path, then you have two options: use commercial services such as Windows Azure for storage, or use IsolatedStorage local interface. IsolatedStorage allows you to store files for use only by your application.
Depending on how your data is stored in your applications, you may want to store data locally without the need to create and use a database. For example, if you create an RSS / Podcast application, you can simply store XML from an RSS feed. If you need to access data, simply load the data and use LINQ (Language Integrated Query) to get specific data.
In the RSS application example, we can either work with the original XML from the RSS feed, or we could use LINQ for XML to create an XDocument to store the entries, as shown below:
//Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  1. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  2. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  3. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  4. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  5. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  6. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  7. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
  8. //Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .
//Create XML XDocument doc = new XDocument (); doc.Add( new XElement ( "DataRoot" , new XElement ( "Record" , new XElement ( "value" , "data1" )), new XElement ( "Record" , new XElement ( "value" , "data2" )) )); * This source code was highlighted with Source Code Highlighter .

The XML generated by this simple code snippet looks like this:
  1. < DataRoot >
  2. < Record >
  3. < value > data1 </ value >
  4. </ Record >
  5. < Record >
  6. < value > data2 </ value >
  7. </ Record >
  8. </ DataRoot >
* This source code was highlighted with Source Code Highlighter .

To save this XML in isolated storage, we use IsolatedStorageFile with an IsolatedStorageFileStream, as shown in the following snippet:
  1. // Save the XML
  2. using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ())
  3. {
  4. using (IsolatedStorageFileStream file = isf.OpenFile ( "data.xml" , FileMode .OpenOrCreate))
  5. {
  6. doc.Save (file);
  7. file.Close ();
  8. }
  9. }
* This source code was highlighted with Source Code Highlighter .

As you can see, it is very easy to implement storing XML data in isolated storage. The code for getting the XML and creating the LINQtoXML query is shown below:
  1. // Load the XML
  2. using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ())
  3. {
  4. using (IsolatedStorageFileStream file = isf.OpenFile ( "data.xml" , FileMode .OpenOrCreate))
  5. {
  6. XDocument d = XDocument .Load (file);
  7. var query = from r in d.Root.Elements ( "Record" )
  8. select r;
  9. // Process the list of record
  10. }
  11. }
* This source code was highlighted with Source Code Highlighter .

Although the example above is very simple, it illustrates how easy it is to implement data storage on your phone without the need to create and use a database. This code can also be extended to store more complex data.

Development tools


As an Android developer, you are most likely accustomed to the good and bad side of open-source development. Using IDE Eclipse for Android is, of course, part of the good side. But the Android Development Toolkit (ADT) lacks many necessary tools, such as proper markup tools. Although ADT actually provides these tools, they are not reliable enough so that you can easily create markup - most likely you will have to dive into XML.
Microsoft has provided reliable development tools for many years. And the Windows Phone 7 platform is no exception. Microsoft, as usual, allows you to quickly and easily start development. Java developers can download and try these tools without spending any money.
Currently, the following tools are available at create.msdn.com :
These three tools allow you to start creating applications for Windows Phone 7 for free.
Microsoft Visual Studio 2010 Express for Phone is the main integrated development environment (IDE) used to create applications for Windows Phone 7. It includes all the tools you need to create applications, including the Page Markup Tool, the C Compiler #, Windows Phone 7 emulator and more.
Microsoft Expression Blend for Phone is a tool aimed primarily at professional designers and is used to improve Pages in a Silverlight application. Developers can use this tool to create pages from scratch or improve the Pages of an existing application without affecting its code.
Microsoft XNA Game Studio for Phone provides a set of tools needed to create 2D and 3D games for the platform. Studio also includes the XNA Framework, as well as the tools you need to turn on the audio and graphics needed to create loop-based games.

Conclusion


Windows Phone 7 offers a new approach to the operating system for smartphones, but it is still based on proven technologies such as Silverlight, WPF, C #, and many others. As you can see from this article, the differences between Android and Windows Phone 7 are not that great.

UPD: I published a translation of this article in order to show that it is not so difficult to study development for the Windows Phone 7 platform if you already have development experience for Android. It does not say that any of these mobile platforms is better or worse.
Please do not drive my karma into a minus so that I can publish other articles on developing for Windows Phone 7. If you are not interested, pass by, do not deprive of the opportunity to learn something new to those who are interested.

Source: https://habr.com/ru/post/117134/


All Articles