Going from Android to Windows Phone 7 Development
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 in Android 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.
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. Stay tuned for an upcoming segment on How To Style Windows Phone 7 Apps in Expression Blend.
If you liked this example/article then you may also like the upcoming From iPhone to Windows Phone 7 Development.
Note: I want to have a special note here to explain my deathly sickening experiences I have had setting up Android inside of Eclipse. After numerous installation errors and ten times as many IDE crashes I managed to build this small app. Astounding!! I am shocked by the quality of the software. My experiences inside of Visual Studio 2010 and Expression Blend 4 were much better. I never had a single crash and it’s still beta software. Point is, the dev tools for Android are laughable at best in comparison to the beauty and elegance of Microsoft dev tools. Sorry to keep mentioning it in all my articles. I just can’t help it! I swear I’ll stop being mean when Google and Apple start considering the toils of a developer.













[...] This post was mentioned on Twitter by Fay Santiago, Ariana, Intergalactic Mktg, Little Black Agency, ArianaFaustini and others. ArianaFaustini said: RT @DirtyDeveloper: Going from #Android 2 #WindowsPhone7 Development – with the source code http://bit.ly/cDl7Z8 #WP7 #wp7dev [...]
[...] the scene is Mishkin Faustini, who is a fan of Windows Phone 7, so that bias should be considered, but he does a nice job of comparing and contrasting the two platforms finally mentioning that …the dev tools for Android are laughable at best in comparison to the [...]
[...] the scene is Mishkin Faustini, who is a fan of Windows Phone 7, so that bias should be considered, but he does a nice job of comparing and contrasting the two platforms finally mentioning that …the dev tools for Android are laughable at best in comparison to the [...]
Interesting– For what it’s worth, I had the opposite experience. The android SDK and development environment installed seamlessly, and the Windows Phone 7 SDK wouldn’t let me launch the emulator, claiming another hypervisor was running (no other hypervisor had ever been installed).
After the read, looks like WP7 Development is definitely easier then Andriod.
Yes, I have had a few issues uninstalling the CTP version of Windows Phone dev stuff but lets remember this is all pre-release software. For more on that visit http://blogs.msdn.com/b/astebner/archive/2010/07/12/10037442.aspx . Are we are actually comparing pre-release software to not only final version software but froyo which is version 2.2!? It’s no question in my mind that Androids tools lack.
Anyway if you’d like to see I kept a few snapshots of the errors eclipse would just chuck at me every two minutes:
http://www.thedirtydeveloper.com/wp-content/uploads/2010/07/eclipseerror1.png
http://www.thedirtydeveloper.com/wp-content/uploads/2010/07/eclipseerror2.png (and my permgen space was set to be large)
http://www.thedirtydeveloper.com/wp-content/uploads/2010/07/eclipseerror3.jpg
Mind you, I use Eclipse on a daily basis in my full time job. I think it’s a decent IDE but still no where near as polished as VS2010.
I certainly believe so! I hope I can prove it to people since I have done full Android development from the very first days of Android. Perhaps that gives me more say in the matter?
HTC Porting Sense UI To Windows Phone 7…
http://www.engadget.com/2010/07/24/…ne-7-after-all/One of the consequences of Microsoft’s lockdown of Windows Phone 7 specifications was that 3rd party UIs were essentially left out in the cold. Now it seems that the restriction is not going to be a…
What is happening here?
[...] Read more detail at the DirtyDeveloper.com here. [...]
Going from Android to Windows Phone 7 Development | the Dirty Developer…
Thank you for submitting this cool story – Trackback from DotNetShoutout…
[...] dirtydev [...]
[...] Dirty Developer had recently compared Android and Windows Phone 7 development and while for a simple application [...]
Google Nexus One now available, yet again, for Android devs only…
If you could not manage to get yourself a Google Nexus One and still want to give it a try, this day might be your lucky day. You only need to be a registered Android developer and to have some 529 US dollars in the piggy bank. As you might ha…
[...] Source: The Dirty Developer [...]
You might get this if you are running a virtual image – (My understanding is that as the WP7 emulator is a virtual image itself you cannot run it under another VM).
hi, this is an awesome post for android and wp7dev. I am surprised about the note at the end, however. Is your machine 64-bit? I wrote up a post about my experience doing a hello world here http://www.androidhot.com/post/G-1-Review-Part-1.aspx my experience went smooth. cheers,
G-
[...] El segundo artículo también procede del blog de un desarrollador. En este caso utiliza un vídeo para detallar los pasos para crear una aplicación en Windows Phone 7 frente a los necesarios para crearla en Android 2.2. En este caso los lenguajes de programación, C# en el caso de WIndows Phone 7 y Java en el caso de Android, son más similares. El primer paso en ambos casos es el de crear la estructura en XML, también de forma bastante similar. [...]
I doubt the way ppl says Android Eclipse crash etc. Not sure what wrong they do. But I am using android almost daily never had issues…
Have spent more than two years developing for Android and less than 6 months with W7 tools, primarily Visual Studio and not much of Expression.
It took a while to get used to Silverlight concepts, almost same time I took to get at ease with Android. Once I crossed the basics, have to admit, I am blown away with XAML’s capabilities. What Andorid is missing is something truely equivalent to XAML.
It doesn’t matter, does it?
We can still build compelling UI with Android SDK.
As much as I have my bias towards preferred platform, if I see the depth and capabilities of the development platforms, I have to admin Silverlight and XAML are far ahead.
As a developer, I am willing to put in extra effort to build Android apps. What matters is excitement and acceptance of the product (the phone) by the masses. For that, WP7 has a looooong way to go…
If MSFT can gain some market penetration, Android has a real challenge from development experience perspective.
Visual Studio has always been better (IMHO) than Eclipse, but Eclipse is by no means a bad IDE. It is quite capable, and once you get used to its workflow, it is very productive.
I’m not sure why the author had so many problems. I had my first hello world Android app up and running in about 30 minutes. I have had only one development crash in the past month (my first month of Android dev), and it wasn’t Eclipse crashing. The emulator crashed — or at least the part that allows debugging (project wouldn’t deploy in debug mode). I restarted the emulator and all was well.
The biggest downer in Android land is the lack of a decent visual layout editor. The integrated one with Eclipse is really crap, and the few online tools out there (like DroidDraw) are not much better. I find it’s faster to type out the XML by hand and launch it in the emulator to view layout. This is extremely slow compared to Expression or Visual Studio mockups and layouts. I was hoping Google’s new App Inventor would allow decent mockup and autogenerated XML, but, again, it falls very short in this respect.
All that said, what does all this really matter? Apple uses Objective-C and forces you to buy a Mac to develop on iPhone. If you aren’t an Apple fanboy, the only words out of your mouth at that thought is, “Ugh.” Objective-C is absolutely atrocious, and a Mac is a high dollar investment if you are only getting it for iPhone development (especially for hobbiests). But its the price you pay to enter the market. In other words, it’s not nice development tools that drive developers to your device. It’s the userbase that does.
Microsoft could write an app that reads your mind and developes 90% of the code while you are asleep and dreaming, but it wouldn’t matter if nobody is buying the device!
Hopefully Android will get a visual designer, WP7 will get more features and users, and iPhone will become irrelevant. That would be ideal.
AbsoluteLayout is not equal Grid tag, and so on so
foth
Thanks for the nice post.
We are also working on both android and WP7 application development.
http://www.synapse.co.in/solutions/windows_phone7.shtml
Leave your response!
Like the Dirty Developer on Facebook
Blogroll
WP7 Videos
Staggering animations in Windows Phone 7 is simple. Visit http://www.thedirtydeveloper.com for full source and tutorials.
YouTube Plugin made by Web Hosting.
Most Commented
Most Viewed