<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Making the Complex Simple &#187; Mobile</title>
	<atom:link href="http://simpleprogrammer.com/category/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://simpleprogrammer.com</link>
	<description>Software Development from John Sonmez&#039;s Perspective</description>
	<lastBuildDate>Tue, 07 Feb 2012 17:47:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='simpleprogrammer.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Making the Complex Simple &#187; Mobile</title>
		<link>http://simpleprogrammer.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://simpleprogrammer.com/osd.xml" title="Making the Complex Simple" />
	<atom:link rel='hub' href='http://simpleprogrammer.com/?pushpress=hub'/>
		<item>
		<title>MonoTouch</title>
		<link>http://simpleprogrammer.com/2011/10/30/monotouch/</link>
		<comments>http://simpleprogrammer.com/2011/10/30/monotouch/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 02:33:24 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[MonoTouch]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1408</guid>
		<description><![CDATA[I’ve been so busy lately that I have neglected to write about a great platform for developing iOS applications called “MonoTouch.” I recently released a new course on MonoTouch at Pluralsight. I wanted to take a bit of time here to talk about MonoTouch and to tell you why you should be using it instead [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1408&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been so busy lately that I have neglected to write about a great platform for developing iOS applications called “<a href="http://xamarin.com/monotouch">MonoTouch</a>.”</p>
<p>I recently released a <a href="http://www.pluralsight-training.net/microsoft/courses/TableOfContents?courseName=mono-touch">new course on MonoTouch</a> at Pluralsight.</p>
<p>I wanted to take a bit of time here to talk about MonoTouch and to tell you why you should be using it instead of developing iOS applications in Objective-C</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/10/text-monotouch.png"><img style="background-image:none;padding-left:0;padding-right:0;display:block;float:none;margin-left:auto;margin-right:auto;padding-top:0;border-width:0;" title="text-monotouch" src="http://complextosimple.files.wordpress.com/2011/10/text-monotouch_thumb.png?w=175&#038;h=55" alt="text-monotouch" width="175" height="55" border="0" /></a></p>
<h2></h2>
<h2>Flipping directions</h2>
<h2><a href="http://complextosimple.files.wordpress.com/2011/10/gophoto_0197_scanned-image-00363.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="GoPhoto_0197_Scanned-Image-00363" src="http://complextosimple.files.wordpress.com/2011/10/gophoto_0197_scanned-image-00363_thumb.jpg?w=506&#038;h=334" alt="GoPhoto_0197_Scanned-Image-00363" width="506" height="334" border="0" /></a></h2>
<p>When I first started developing with iOS, I firmly believed that the job should be done using the tools that Apple provided.</p>
<p>I still think it is a very good idea to learn Objective-C and how to develop an iOS application using Objective-C and XCode.</p>
<p>But I am convinced now that overall MonoTouch is the way to go.</p>
<p>Objective-C is a decent language, but it has a fairly steep learning curve for a C# or Java developer.  XCode, the IDE for developing iOS applications, is a decent IDE, but it is not nearly as powerful as MonoDevelop or Visual Studio.</p>
<p>The reality of the situation is that Apple’s development platform is still back in 1990.  Even though there have been some changes and growth, I firmly believe now that Objective-C and the underlying technology cannot ever catch up to .NET or Java.</p>
<p>I don’t say this lightly.  As I said, before I developed a fairly large application in Objective-C.  I authored a <a href="http://www.pluralsight-training.net/microsoft/Courses/TableOfContents?courseName=ios-intro">Pluralsight course on iOS</a> development with Objective-C.  I was pretty convinced this was the way to go until I gave MonoTouch a try.</p>
<h2></h2>
<h2>An unfair test</h2>
<p>I really gave MonoTouch an unfair test, but it passed anyway.  I set out to learn, configure, build a MonoTouch application, and deploy it to the Apple App Store in 1 weekend.</p>
<p>I figured if MonoTouch could pass this test then I would immediately save more than the $400 cost for the software since the next application I was going to build was going to probably take at least a week worth of time to build in Objective-C.</p>
<p>MonoTouch easily passed my test and really exceeded my expectations.</p>
<h2>The main advantage</h2>
<p>By and far the main advantage in using MonoTouch is the language.</p>
<p>C#’s ability to wire up events through event handlers and delegates makes working with iOS so much easier.</p>
<p>There are many situations in iOS where you have to create a special class to act as a delegate for providing behavior for various iOS controls and classes.  In C#, many of these delegate classes can be replaced by a C# delegate or lambda expression.</p>
<p>Another really painful situation in Objective-C is memory management.  If you aren’t used to tracking memory usage it takes a bit to get adjusted to it in Objective-C.  Sure, it really isn’t that hard, but once I started working with C# to build my iOS application, I realized how much faster I could fly through the code without having to even think about it.  (The newer version of Objective-C has somewhat built in memory management, but it is not a true garbage collection implementation.)</p>
<p>Along with C#, you get the full power of the .NET framework.  Almost all of the base class libraries from .NET are available in MonoTouch.  (You basically have the silverlight .NET profile.)</p>
<p>This really comes in handy in 3 main areas:</p>
<ul>
<li>Working with XML</li>
<li>Working with databases</li>
<li>Calling web services</li>
</ul>
<p>If you try to do these things in Objective-C, it is possible, but it will hurt like hell.</p>
<h2>Give it a shot</h2>
<p>If you are interested in developing iOS applications and you haven’t tried MonoTouch, go give it a try.  Trust me, it is worth the effort.  One of the big factors that had me developing Android applications and shying away from iOS was the hurdle of trying to learn and work with Objective-C.</p>
<p>MonoTouch lets you reuse your C# skills without any extra overhead, since the application is compiled down to native ARM assembly code.</p>
<p>If you don’t know where to get started or want to learn a little bit more about MonoTouch, feel free to check out <a href="http://www.pluralsight-training.net/microsoft/courses/TableOfContents?courseName=mono-touch">my course on Pluralsight</a>.</p>
<p>Kudos to the <a href="http://xamarin.com/">Xamarin</a> team for building such a great product!</p>
<p><em>(BTW, that photo is me flipping.  Actually it is a thing I used to call “throwing myself at the ground for dramatic effect.”)</em></p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1408/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1408/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1408/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1408&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/10/30/monotouch/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/10/text-monotouch_thumb.png" medium="image">
			<media:title type="html">text-monotouch</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/10/gophoto_0197_scanned-image-00363_thumb.jpg" medium="image">
			<media:title type="html">GoPhoto_0197_Scanned-Image-00363</media:title>
		</media:content>
	</item>
		<item>
		<title>PaceMaker for iPhone Released</title>
		<link>http://simpleprogrammer.com/2011/06/09/pacemaker-for-iphone-released/</link>
		<comments>http://simpleprogrammer.com/2011/06/09/pacemaker-for-iphone-released/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 03:47:52 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/06/09/pacemaker-for-iphone-released/</guid>
		<description><![CDATA[Earlier this year I announced the release of an app I had been working on for Android called PaceMaker. Finally, I have succeeded in porting the application over to iPhone and it was definitely much harder than I had anticipated. But I am glad to announce that as of today you can find PaceMaker for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1349&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Earlier this year <a href="http://simpleprogrammer.com/2011/01/04/introducing-pacemaker-for-android/">I announced the release of an app I had been working on for Android called PaceMaker</a>.</p>
<p>Finally, I have succeeded in porting the application over to iPhone and it was definitely much harder than I had anticipated.</p>
<p>But I am glad to announce that as of today you can find <a href="http://itunes.apple.com/us/app/pacemaker-running/id441825091?mt=8&amp;ls=1">PaceMaker for iPhone in the Apple App Store</a>.</p>
<p>If you don’t know what PaceMaker is, you can read about it in my original post above or in the description in the app store, but to sum it up briefly, it helps you run at a desired pace by telling you to speed up or slow down when you are running too fast or too slow.</p>
<p align="center"><a href="http://complextosimple.files.wordpress.com/2011/06/default2x.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Default@2x" border="0" alt="Default@2x" src="http://complextosimple.files.wordpress.com/2011/06/default2x_thumb.png?w=324&#038;h=485" width="324" height="485" /></a></p>
<h2></h2>
<h2>A unique perspective</h2>
<p>Having originally written the application and then porting it over to iPhone gives me a kind of unique perspective on mobile development platforms.</p>
<p>Although it was a bit painful at times to basically recreate the same thing I already spent so much time and energy creating, I was able to very realistically contrast the two development platforms in many areas.</p>
<p>One of the major pain points I experienced was in documentation.&#160; Google’s documentation on the Android platform is sometimes lacking, but is much more complete and descriptive than Apple’s iOS documentation.</p>
<p>I am still quite a bit torn on which platform I like more and which platform I think will win out in the end.&#160; I do believe that if Apple improved their developer tools and moved to a new, more modern development language, that they would have a distinct advantage.</p>
<p>It seems to me though that whoever integrates the best across multiple devices and gets the highest quality applications built for their platform will be the winner.&#160; iCloud could be a huge step in that direction for Apple.</p>
<h2>Sharing the knowledge</h2>
<p>I’ve just talked with my curriculum director at <a href="http://www.pluralsight-training.net/microsoft/">Pluralsight</a> and I will be doing a beginning iPhone development for .NET developers course just like the <a href="http://www.pluralsight-training.net/microsoft/OLT/Course/Toc.aspx?n=android-intro">Android Development for .NET Developers</a> course I did earlier this year.</p>
<p>I’m pretty excited to do this because I am going to try and draw some major parallels between the two platforms and also from the .NET perspective.</p>
<p>I hope to create the course just like the Android one, where we will step by step create an application from scratch and then publish it to the Apple App Store.</p>
<p>Look for that in the next few months on Pluralsight.net.</p>
<h2>Dailymile.com integration</h2>
<p>Also included with this release for iPhone and Android is Dailymile.com integration.&#160; I think this feature is pretty cool!&#160; So I am really excited about it!</p>
<p>Dailymile.com is basically a social site for runners and cyclists.&#160; It is basically a Facebook for runners.</p>
<p>I have added a feature to the Android and iPhone versions of PaceMaker to allow you to post your run details, including the GPX map of your run, up to the Dailymile.com server on your wall.</p>
<p>So when you go for a run you can capture all the information from your run and see it on Dailymile.com.</p>
<p>This was quite a pain to implement as I had to implement OAuth2 authentication in both platforms and integrate with a REST API.&#160; But what a great learning experience!</p>
<p>Anyway, if you are a runner out there and you get PaceMaker, feel free to send me an email or drop me a comment.&#160; I am always looking for feedback so I can improve the app.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1349&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/06/09/pacemaker-for-iphone-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/06/default2x_thumb.png" medium="image">
			<media:title type="html">Default@2x</media:title>
		</media:content>
	</item>
		<item>
		<title>OAuth and REST in Android: Part 2</title>
		<link>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/</link>
		<comments>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 20:49:34 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/2011/06/04/oauth-and-rest-in-android-part-2/</guid>
		<description><![CDATA[In my last post we went over OAuth in general and we looked at how to use a Java library called Leeloo to authenticate with a service providing an OAuth 2 implementation. Now that we are able to authenticate a service with OAuth, we need to be able to actually use that service to do [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1346&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/">last post</a> we went over OAuth in general and we looked at how to use a Java library called Leeloo to authenticate with a service providing an OAuth 2 implementation.</p>
<p>Now that we are able to authenticate a service with OAuth, we need to be able to actually use that service to do something useful.</p>
<p>Many popular web service APIs like Facebook and Twitter provide a REST based implementation.</p>
<p>In this post I’ll show you how to easily connect to one of these web services from Android and parse any responses you get back.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/06/androidrest.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="AndroidREst" border="0" alt="AndroidREst" src="http://complextosimple.files.wordpress.com/2011/06/androidrest_thumb.png?w=422&#038;h=366" width="422" height="366" /></a></p>
<h2></h2>
<h2>Should I use a REST library?</h2>
<p>This is a valid question we should address before getting into the details.</p>
<p>My answer to this question is basically “no.”</p>
<p>I first tried the approach of using a REST library to make it easier to communicate to a REST based web service, but quickly found the overhead of the library was more than the benefit it provided.</p>
<p>If you come from a background of calling XML and SOAP based web services, you might be surprised by this answer.&#160; With SOAP based web services it was a huge benefit to use a library to generate a proxy for you to call the web service and let you not have to worry about parsing XML and SOAP headers.</p>
<p>With REST it is completely different.&#160; The whole point of moving to REST based web services is to simplify the process of calling web services.</p>
<p>Most REST based web service interfaces are extremely simple to use.&#160; The idea is that the URL itself contains as much of the data as possible and additional data is included in the POST body.</p>
<p>By adding the complexity of learning a REST library and implementing the proper interfaces required to make it work seamlessly, we can easily add more complexity and overhead than just creating a HTTP request ourselves and parsing the responses.</p>
<p>For this approach I am going to show you how to do just that.</p>
<h2></h2>
<h2>Calling the REST service</h2>
<p>In order to call a REST service in Android we are going to first have to discover and understand the REST API provided to us, then make the appropriate calls with the OAuth token we got from authenticating.&#160; Finally, we will parse the result of the call and get back our response.</p>
<p><strong>Discovering the API</strong></p>
<p>Because REST is not really a standard, but rather an ideal, there is not a standard way REST APIs are implemented.</p>
<p>You’ll have to take a look at the documentation for the REST API you want to call to figure out exactly what a call should look like.</p>
<p>In general though a REST API will involve making some kind of HTTP GET, POST, PUT or DELETE request and passing data through the URL or in the request body.</p>
<p>Here is an example of the Dailymile.com API which I have been recently integrating my app to use.</p>
<p>You can see the full <a href="http://www.dailymile.com/api/documentation">API documentation here.</a></p>
<p>For this API, I am going to show you how I am creating a workout entry using a post.</p>
<p><strong>Making the REST call</strong></p>
<p>In order to make a REST call in Android, we are going to use a <em>HttpClient</em> object and the appropriate http request class.</p>
<p>In this example we are going to use the JSONObject class to create some data in JSON format that we can pass to the REST call by embedding it in the post.</p>
<p>I looked at the API for posting a workout entry to Dailymile, and the format of the request should look like this:</p>
<p><a title="https://api.dailymile.com/entries.json?oauth_token=" href="https://api.dailymile.com/entries.json?oauth_token">https://api.dailymile.com/entries.json?oauth_token=</a>&lt;token&gt;</p>
<p>The API also indicates that it expects the post body to contain some JSON and gives us a list of required and optional entries that need to be in that JSON object.</p>
<p>Let’s take a look at how I am making this call and then we’ll break it down some.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:f8610da6-d295-47dd-9ae4-a02b7d443e4f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: java; pad-line-numbers: true;">
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(
	&quot;https://api.dailymile.com/entries.json?oauth_token=&quot; 
    + token);

httpPost.setHeader(&quot;content-type&quot;, &quot;application/json&quot;);
JSONObject data = new JSONObject();

data.put(&quot;message&quot;, dailyMilePost.getMessage());
JSONObject workoutData = new JSONObject();
data.put(&quot;workout&quot;, workoutData);
workoutData.put(&quot;activity_type&quot;, dailyMilePost.getActivityType());
workoutData.put(&quot;completed_at&quot;, dailyMilePost.getCompletedAt());
JSONObject distanceData = new JSONObject();
workoutData.put(&quot;distance&quot;, distanceData);
distanceData.put(&quot;value&quot;, dailyMilePost.getDistanceValue());
distanceData.put(&quot;units&quot;, dailyMilePost.getDistanceUnits());
workoutData.put(&quot;duration&quot;, dailyMilePost.getDurationInSeconds());
workoutData.put(&quot;title&quot;, dailyMilePost.getTitle());
workoutData.put(&quot;felt&quot;, dailyMilePost.getFelt());

StringEntity entity = new StringEntity(data.toString());
httpPost.setEntity(entity);

HttpResponse response = httpClient.execute(httpPost);
</pre>
</pre>
</div>
<p>&#160;</p>
<p>You can see that I am first creating an <em>HttpClient</em> object and an <em>HttpPost</em> object.&#160; The <em>HttpPost </em>has its URL set to the URL for the API call and I am adding a query string parameter to provide the OAuth token we got when when authenticated in my <a href="http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/">previous post</a>.</p>
<p>I set the content type to be JSON so that we can get back a JSON object from the API call and so it knows that we are passing JSON data.</p>
<p>Then I construct a JSON object in the format specified by the API.&#160; The way to construct the JSON object is to basically create a set of keys and values that are specified by the API you are calling.&#160; In this instance I have a “message” key which I put the message data into.&#160; </p>
<p>The only tricky part is that JSON objects can be nested.&#160; So if you look at the key “workout” in the example above, I am creating a brand new JSON object to use as the value for that key which has its own subkeys which could contain more JSON objects.</p>
<p>Doing it this way is much more simple than trying to construct the string yourself.&#160; The string we end up constructing will look something like this:</p>
<blockquote>
<pre>{&quot;message&quot;:&quot;fun!&quot;,&quot;workout&quot;:{&quot;distance&quot;:{&quot;value&quot;:5,&quot;units&quot;:&quot;miles&quot;},</pre>
<pre>&quot;activity_type&quot;:&quot;running&quot;}}</pre>
</blockquote>
<pre><font face="Verdana"></font>&#160;</pre>
<div>
<pre><font face="Verdana">Finally, I put the JSON data into a <em>StringEntity</em> class and set it as the entity on the HTTP Post.  Then we can call execute on the <em>HttpClient</em> to execute the HTTP POST.</font></pre>
</div>
<div>
<pre><font face="Verdana"></font>&#160;</pre>
</div>
<div>
<pre><font face="Verdana"><strong>Handling the response</strong></font></pre>
<pre><strong><font face="Verdana"></font></strong></pre>
</div>
<div>
<pre><strong><font face="Verdana"></font></strong></pre>
</div>
<div>Now that we have actually made the call to the REST service method we can handle the response by creating another JSONObject from the HttpResponse that is returned.</div>
<div>&#160;</div>
<div>Let’s look at that code and then we can go over what is happening.</div>
<div>&#160;</div>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:6c90c3b6-702d-4830-b348-12d2efb89b0a" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: java;">
HttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
JSONObject responseJSON = new JSONObject(responseString);
int workoutId = responseJSON.getInt(&quot;id&quot;);
</pre>
</pre>
</div>
<p>All we are doing in this case is getting the response from the execute call on the <em>HttpClient</em> object, then using <em>EntityUtils.toString</em> to convert the response’s entity to a string representation.&#160; Finally, we construct a new <em>JSONObject</em> from that string.</p>
<p>We can then easily extract any data out of the JSON object by using the methods on that JSON object that let us get typed values out of it.&#160; For this example, I know that I am getting back some JSON that has a key “id” which is the id of the workout I created with my POST.</p>
<h2>It is really that simple</h2>
<p>The example I am showing you here is one of the more complex examples of calling a REST based API, because we are having to POST and parse JSON data.</p>
<p>In many API calls, you can just use an HTTP GET or a POST without any data to accomplish what you need to in the API.</p>
<p>Some REST based APIs will allow or require data to be passed in a different format, but most of them use JSON notation, which I find the easiest to work with.</p>
<p>Hopefully with these series of posts you can now authenticate against an OAuth 2 based service and make calls to the API to get and manipulate data in Android.</p>
<p>If you have any questions, feel free to drop me a line or post in the comments below.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.&#160; Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.&#160; Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1346&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/06/04/oauth-and-rest-in-android-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/06/androidrest_thumb.png" medium="image">
			<media:title type="html">AndroidREst</media:title>
		</media:content>
	</item>
		<item>
		<title>OAuth and REST in Android: Part 1</title>
		<link>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/</link>
		<comments>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/#comments</comments>
		<pubDate>Wed, 25 May 2011 18:02:47 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1338</guid>
		<description><![CDATA[I recently had the fun experience of learning a bit about both OAuth and making REST web service calls in Android and since I didn’t find much good material out there, I thought I would share it here. Let&#8217;s talk about OAuth The first thing you NEED to know about OAuth is that OAuth and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1338&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently had the fun experience of learning a bit about both OAuth and making REST web service calls in Android and since I didn’t find much good material out there, I thought I would share it here.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/05/oauthpicture.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="OAuthPicture" src="http://complextosimple.files.wordpress.com/2011/05/oauthpicture_thumb.png?w=467&#038;h=259" alt="OAuthPicture" width="467" height="259" border="0" /></a></p>
<h2>Let&#8217;s talk about OAuth</h2>
<p>The first thing you NEED to know about OAuth is that OAuth and OAuth 2.0 are not the same protocol.</p>
<p>From the <a href="http://hueniverse.com/2010/05/introducing-oauth-2-0/">OAuth guide</a> on hueniverse:</p>
<blockquote><p><strong>OAuth 2.0 is a completely new protocol</strong> and is not backwards compatible with previous versions. However, it retains the overall architecture and approach established by the previous versions, and the same introduction (from the Official Guide to OAuth 1.0) still very much applies.</p></blockquote>
<p>But, before we get into that, let’s talk a little bit about what OAuth is for.</p>
<p>OAuth basically does two things for a web site providing some kind of service or API that another application might want to use.</p>
<ol>
<li>It prevents the consuming application from needing to store or have the user’s login and password.</li>
<li>It allows for a scoping of access to the producer’s services.  (For example, a user might be able to login to a site and access all of the features, but an app using OAuth might only be granted permissions to do certain things.)</li>
</ol>
<p>So now that we know why, let’s talk about how both OAuth and OAuth 2 work from a high level perspective.</p>
<p>From the app developer perspective, the flow goes something like this:</p>
<ol>
<li>You register your application with the service you want to access and get some unique identifiers for your application.</li>
<li>When you want to access something on the service, you make a request to the service using your unique identifier and telling it where to send the user after they authenticate.  (Usually you would launch a browser window here.)</li>
<li>User will login to the service using the browser window you launched for that service and choose to grant your application certain privileges.</li>
<li>The service will redirect the user to the callback url you provided and include a code you can use to get an access token.</li>
<li>You call the service one more time passing in your unique identifier and the code you got back and the service grants you an access token which you can use to access services you have been granted permissions for.</li>
<li>The next time you need to make a call you can just use that access token instead of going through this whole process again.  (At least till it expires.)</li>
</ol>
<p>It really isn’t that complicated; the basic idea is that you tell the service who you are and ask the user the authenticate themselves and grant permissions to your application.  Then you prove that you got the response from the server and that it is still you and the service gives you a special pass to access the service.</p>
<p>The real difference between OAuth and OAuth 2 is the protocol itself, not the process.  So this is both good and bad.</p>
<p>Good, because we don’t have to change our process flow and understand something different.</p>
<p>Bad, because we can’t use the same libraries to access an OAuth 2 implementation as we do for an OAuth implementation and vice versa.  There is no backwards compatibility.</p>
<p>For the purpose of this post I am going to show how to use the <a href="https://bitbucket.org/smartproject/oauth-2.0/wiki/Home">Leeloo library</a> to connect to an OAuth 2 service.</p>
<h2></h2>
<h2></h2>
<h2></h2>
<h2>Connecting to OAuth 2.0</h2>
<p><strong>Download the library</strong></p>
<p>The first thing you will want to do is to get the latest version of the Leeloo library.  It has moved to the Apache Amber project, so this link might change, but for now I found the <a href="https://bitbucket.org/smartproject/oauth-2.0/wiki/Home">ready to download binaries here</a>.</p>
<p><strong>Configure build path</strong></p>
<p>Once you have the library downloaded you’ll want to add the following jars to your build path:</p>
<ul>
<li>jettison-1.2.jar</li>
<li>oauth2-client.jar</li>
<li>oauth2-common-0.1.jar</li>
<li>slf4j-api.1.6.1.jar</li>
</ul>
<p><strong>Make initial request for authorization</strong></p>
<p>Make sure you already have a unique client id created with the service you are going to access.  Most services out there like Twitter have a page where you can request one for your application.</p>
<p>Once you have this, you will use this to create a url that you will redirect the user of your application to.</p>
<p>In the code snippet below, I am creating the url and then creating a new Intent in Android that will open a web browser at that url.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:b54fdd53-471a-4d5b-bcfe-90cede501c10" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java; pad-line-numbers: true;">
OAuthClientRequest request = null;
request = OAuthClientRequest
       .authorizationLocation(authenticationUrl)
	   .setClientId(&quot;&lt;your client id&gt;&quot;).setRedirectURI(&quot;&lt;your redirect url&gt;&quot;)
		.buildQueryMessage();

Intent intent = new Intent(Intent.ACTION_VIEW,
        Uri.parse(request.getLocationUri() + &quot;&amp;response_type=code&quot;));
startActivity(intent);
</pre></p>
</div>
<p>A couple of things to note about this code snippet:</p>
<ul>
<li>You’ll need to replace client id with your client id and redirect URI with your redirect URI.</li>
<li>The redirect URI for an Android application is going to be some protocol that doesn’t really exist, but you can tell your application to respond to.  (We’ll cover that in the next step, but you might have some URI like myapp://oauthresponse)</li>
<li>I had to add a “&amp;response_type=code” to the end of my URL because the authentication service required it.  You might have to look and see how the service you are trying to access expects requests to be formed.</li>
</ul>
<p><strong>Configure your application to respond to your unique URI</strong></p>
<p>In the previous step we had set the redirect to a unique URI like “myapp://oauthresponse”, now you will need to configure the activity you want to handle the response from the service to intercept that protocol.</p>
<p>You can do this by adding an intent filter to that activity like so:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:159a20e7-915a-4838-ae21-d2f51631ac80" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: xml;">
&lt;intent-filter&gt;
	&lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;
	&lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
	&lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;
	&lt;data android:scheme=&quot;myapp&quot; android:host=&quot;oauthresponse&quot;/&gt;
&lt;/intent-filter&gt;
</pre></p>
</div>
<p>With this intent filter we are telling our activity to respond to a URI request in the form of “myapp://oauthresponse”.</p>
<p><strong>Configure your activity to respond to handle the intent you registered to receive</strong></p>
<p>Next we’ll want to set up an override in our activity to handle the new intent that will be called on our activity.  We can then pull the code the service gave us out and use that to request a real token.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:8d931558-fd6f-4c02-ab34-70662ddb23dc" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
@Override
protected void onNewIntent(Intent intent)
{
	Uri uri = intent.getData();

   if (uri != null &amp;&amp; uri.toString()
           .startsWith(&quot;myapp://oauthresponse&quot;))
	{
        String code = uri.getQueryParameter(&quot;code&quot;);
        // ...
   }
}
</pre></p>
</div>
<p>This code will allow us to respond to the intent that will be fired by the web browser when the service redirects the user to “myapp://oauthresponse.”</p>
<p><strong>Exchange the code for a token</strong></p>
<p>Next we need to get a real token instead of a code.  When the user typed in their username and password and granted access to our application, the server called our callback URI with a code that we extracted in the last step.</p>
<p>Now we can pass that code back up to the server along with our client secret and client id and get an access token.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:80bbab4b-6883-4451-a09a-7b577db81b4f" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
OAuthClientRequest request = null;

request = OAuthClientRequest.tokenLocation(&quot;&lt;service request URL&gt;&quot;)
	.setGrantType(GrantType.AUTHORIZATION_CODE)
   .setClientId(&quot;&lt;your client id&gt;&quot;)
	.setClientSecret(&quot;&lt;your client secret&gt;&quot;)
	.setRedirectURI(&quot;myapp://oauthresponse&quot;)
	.setCode(code)
	.buildBodyMessage();

OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);
String token = response.getAccessToken();

</pre></p>
</div>
<p>In this bit of code we are sending back to the server all the information we have that identifies our application as well as the code that proves the user allowed us to access that service.</p>
<p>Then we get back an access token from the server.  I would recommend you save this access token so that you don’t have to do this reauthentication in the future.</p>
<h2>Wrapping it up</h2>
<p>So what we have been able to do here is to redirect a user to the right page to authenticate our application, and then wire up our activity to respond to the redirect the service gives us in order to ultimately get an access token we can use to prove we are authorized to access that service on behalf of the user.</p>
<p>Be cautious though, because not everyone is implementing OAuth 2.0 exactly the same way, since the spec is not finalized.  So you might run into issues where things aren’t working exactly as laid out in this post.  If that is the case, you may have to modify a URL that is generated or something along those lines.</p>
<p>In my next post, I’ll show you what you can actually do with your authorization token.  We’ll go through calling a REST based API web service from Android.</p>
<p>Feel free to post any questions in comments.  I used this code to connect to the Dailymile.com API in my <a href="https://market.android.com/details?id=com.pacemaker.android">PaceMaker application</a>.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1338/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1338/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1338/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1338&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/05/25/oauth-and-rest-in-android-part-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/05/oauthpicture_thumb.png" medium="image">
			<media:title type="html">OAuthPicture</media:title>
		</media:content>
	</item>
		<item>
		<title>Published My First Course on Pluralsight</title>
		<link>http://simpleprogrammer.com/2011/04/12/published-my-first-course-on-pluralsight/</link>
		<comments>http://simpleprogrammer.com/2011/04/12/published-my-first-course-on-pluralsight/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 04:27:51 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[Self Improvement]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1305</guid>
		<description><![CDATA[My number of blog posts in the last couple of months has definitely been a little lower than I like, but I have a pretty good reason. I just got my first course published on Pluralsight! The course is called Android Development for .NET Developers and it covers most of the basic knowledge you would [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1305&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My number of blog posts in the last couple of months has definitely been a little lower than I like, but I have a pretty good reason.</p>
<p>I just got my first course published on <a href="http://www.pluralsight-training.net/microsoft/">Pluralsight</a>!</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/04/logomedium1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="logomedium" src="http://complextosimple.files.wordpress.com/2011/04/logomedium_thumb.png?w=233&#038;h=56" border="0" alt="logomedium" width="233" height="56" /></a></p>
<p>The course is called <a href="http://www.pluralsight-training.net/microsoft/OLT/Course/Toc.aspx?n=android-intro">Android Development for .NET Developers</a> and it covers most of the basic knowledge you would need to go from knowing nothing about Android development to being able to create a fairly simple application and publish that application to the Android Market.</p>
<p>If you haven’t checked out <a href="http://www.pluralsight-training.net/microsoft/">Pluralsight</a>, it is a really good site for a wide variety of developer training videos.  They really managed to get some very good content on the site and there are videos on just about every .NET topic you can think of.</p>
<p>I have also really enjoyed working with the guys that run Pluralsight, they are all very friendly and very knowledgeable.  Thanks to <a href="http://twitter.com/elegantcoder">David Starr</a> and <a href="http://twitter.com/fritzonion">Fritz Onion</a> for all their help getting my course ready and published.</p>
<h2>You never really learn something till you teach it</h2>
<p><a href="http://complextosimple.files.wordpress.com/2011/04/teacher-point.gif"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="teacher-point" src="http://complextosimple.files.wordpress.com/2011/04/teacher-point_thumb.gif?w=462&#038;h=425" border="0" alt="teacher-point" width="462" height="425" /></a></p>
<p>This simple truth became more apparent to me than ever during the process of making this course.</p>
<p>I thought I had a pretty good understanding of the Android fundamentals, having published a fairly complex application, <a href="http://simpleprogrammer.com/2011/01/04/introducing-pacemaker-for-android/">PaceMaker</a>.</p>
<p>What I became quickly aware of is that there is a huge difference between having knowledge and having understanding.</p>
<p>I equate knowledge as possessing a formula to be able to do something, but lacking knowing why or how to make modifications to the process.</p>
<p>Cooking provides an excellent example of this.  There are many people in the world who know how to cook a large number of dishes.  But many of these people only have the knowledge of cooking.  They have a large collection of recipes which they can follow to produce the desired result.</p>
<p>A professional chef on the other hand, has a true understanding of cooking.  This person might have knowledge of many recipes, but they also understand why the particular ingredients are used and can make modifications to those ingredients and steps.  They may even create something without preset steps because they understand what they are doing, not just have knowledge about it.</p>
<p>It was great to have the experience of creating these videos because I was able to acquire an in-depth understanding of Android development, not just a knowledge of what to do.</p>
<p>If you ever have the opportunity to teach, I definitely recommend you take that opportunity.  Even if you don’t think you are qualified to teach a subject, by the time you have prepared what you are going to teach, you will be qualified.  Trial by fire perhaps, but well worth the outcome.  Plus you’ll be helping others in the process.</p>
<h2>Much harder than I thought</h2>
<p>I do have to admit though, recording training videos is definitely much harder than I had originally anticipated.</p>
<p>In order to get 40 minutes of video, it might take 6 hours worth of work or even more depending on the prep work involved and how much editing after getting the raw footage.</p>
<p>I really expected that it would take about as much time as it takes to record something to produce that something, but I definitely learned that is not the case.</p>
<p>I often found that I had to draw a line and stop trying to refine a video because you can literally spend an unlimited amount of time editing and tweaking a video.</p>
<p>Another revelation that might be apparent to everyone else, but was quite an epiphany to me was that you can edit “umms” out of video very easily.  You can’t even notice where they are cut out!  My first video, I didn’t even realize I could edit anything, and I ended up taking like 50 cuts until I could get it right.</p>
<h2>Overall though, great experience, lots of fun</h2>
<p>I felt like I&#8217;ve been stretched in a different direction, as I had never done any video or audio recording before and had never really spent much time in a room talking to myself pretending to talk to other people, but it was a good kind of stretching.</p>
<p>I really actually enjoyed the process and I will definitely be doing more of this kind of work in the future.  Probably going to take a bit of a break before I start my next course though.  I want to make sure I take some time to get a good retrospective of the process and sharpen my saw a bit so my next videos can be even better.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1305/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1305&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/04/12/published-my-first-course-on-pluralsight/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/04/logomedium_thumb.png" medium="image">
			<media:title type="html">logomedium</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/04/teacher-point_thumb.gif" medium="image">
			<media:title type="html">teacher-point</media:title>
		</media:content>
	</item>
		<item>
		<title>Objective-C Here I Come!</title>
		<link>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/</link>
		<comments>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 02:39:50 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1244</guid>
		<description><![CDATA[Have I blabbed enough about the PaceMaker app I released for Android yet? First month of sales are over, and it was much better than I had expected.  About 75 purchases in the first 30 days.  Not a huge amount, but that is almost with no advertising, most people who found the app found it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1244&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Have I blabbed enough about the <a href="http://simpleprogrammer.com/2011/01/04/introducing-pacemaker-for-android/">PaceMaker</a> app I released for Android yet?</p>
<p>First month of sales are over, and it was much better than I had expected.  About 75 purchases in the first 30 days.  Not a huge amount, but that is almost with no advertising, most people who found the app found it in the market.</p>
<p>So what is the next step for PaceMaker?</p>
<p>Well, with the <a href="http://support.vzw.com/faqs/iphone/iphone_faq.html">iPhone coming to Verizon this month</a>, I think it is pretty obvious that it is time for the iPhone version.</p>
<p>Only problem is…</p>
<h2>I know nothing about iPhone development!</h2>
<p>Well I didn’t last week, but I am slowly learning.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/02/iphone.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="iphone" src="http://complextosimple.files.wordpress.com/2011/02/iphone_thumb.jpg?w=204&#038;h=370" border="0" alt="iphone" width="204" height="370" /></a></p>
<p>I bought my first Mac ever last week, a <a href="http://www.amazon.com/gp/product/B00487X27O?ie=UTF8&amp;tag=makithecompsi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B00487X27O">MacBook Air</a>.</p>
<p>I have to say, the operating system on Macs has come a long way since I last used one.  (Did I mention I also don’t even know how to properly run a Mac?  But I know Unix, so I should be ok.)</p>
<p>I feel like the Mac interface is so much more polished and uniform than Windows, but it is pretty scary inside when you consider all the low level C and Objective C code.</p>
<p>Then again you have to consider that the wonderful .NET CLR is written right on top of a really crusty win32 API layer which is a bunch of scary C code that is about 20 years old.</p>
<p>So I am setting out on a brave new quest to learn Mac, iPhone and Objective-C and somehow port my application over to the platform.</p>
<h2>Objective-C is kind of like an alternate universe</h2>
<p>I was trying to think how I would describe Objective-C and here is what I came up with:</p>
<blockquote><p>Objective-C is like one of those movies where there is an alternate universe where the same people exist as in this universe, but in some areas their technology is really advanced, but in others it’s really ancient.  Like a bunch of people flying around in flying cars, but their weapons are still bows and arrows.</p></blockquote>
<p>I used to be a C++ programmer, so not too many things scare me, but some of the magical constructs in Objective-C are very frightening indeed.</p>
<p>I was just reading about a strange construct today that allow you to basically create the equivalent of a C# interface, but in Objective-C it is called a “Protocol.”  This seems fine and normal until I read the paragraph that says you can define some of the methods as “Optional.”  What?</p>
<p>Let me put it in C# terms so you can understand it.  In C# it would look like this:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:60464cb2-395c-47e9-9ed3-a55df9c8a2e5" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: csharp; pad-line-numbers: true;">
public interface ILovePuppies
{
   private void HugThem();
   private void SqueezeThem();

   perhaps Corpse KillThem(); // Implement this one
                              //only if you feel like it.

}
</pre></p>
</div>
<p>This is not a joke.  I still can’t quite figure out what this is for, but it is kind of interesting.</p>
<p>Another thing I found interesting is Objective-C has this thing called a “Selector.”  It is not a function pointer, it is a variable that references the name of a method.</p>
<p>How is this different than a function pointer?</p>
<p>It is actually the name of the method being referenced.  So if you have a class Dog that has a method “Wag” and you have a class WildGuesser who has a method “Wag”, passing them the “Wag” selector will cause very different results.  How bizarre.</p>
<h2>It’s weird to get sucked into the Mac world</h2>
<p>It’s actually kind of funny.  Here were all us Java and C# programmers off basically doing the same thing; creating our interfaces and arguing about dependency injection and mocking our unit tests and these Mac geeks with their bow ties and designer jeans were going a totally different direction.</p>
<p>It was only by random chance that our two parallel universes should violently collide.  The iPhone came out and suddenly all these strange “Mac boys” were teaching us this new old language and reminding us to free up own memory again.</p>
<p>FOR GOD&#8217;S SAKE I JUST IMPORTED A C HEADER FILE FOR THE FIRST TIME IN 10 YEARS!  THIS IS CRAZY!</p>
<p>But, I have to admit it is actually kind of fun.</p>
<h2>Sometimes a change of pace is refreshing</h2>
<p>I don’t mean my harsh language to be derogatory towards you Mac heads out there.  You know you are cool, your boy Steve is leading this century&#8217;s computing revolution.</p>
<p>I honestly mean that.  Good job guys, you may just take over the world.</p>
<p>I’m actually enjoying this experience and beginning to think that if I come out alive, I will have gained some very valuable insights into programming in C# and Java.  It is good sometimes to view something from a totally completely different perspective.</p>
<p>Who knows maybe I’ll get to write that Objective-C vs Java vs C# post I&#8217;ve been dreaming of.</p>
<p>But what about…</p>
<h2>MonoTouch?</h2>
<p>Meh.  If I am going to program for a platform, I am going to program for that platform.  I’m not going to half learn how to program for the iPhone and learn on the C# crutch.  I didn’t do that for Android and I’m not going to do it for iPhone either.</p>
<p>Why?</p>
<p>Because I am stubborn and cranky?  Partially, but I actually have a few sensible reasons also:</p>
<ol>
<li><a href="http://monodroid.net/">MonoDroid</a> and <a href="http://monotouch.net/">MonoTouch</a> both implement another layer over the phone’s framework.  Adding this additional layer makes it harder to do low level stuff, and with something as low level as a phone, doing low level stuff is often important.</li>
<li>You are still using the underlying framework for either Android or iPhone.  It is not like using C# code behind the scenes allows you to write a Silverlight UI that you can use on any of the mobile platforms.  You still have to learn the entire phone development framework, which dovetails into point three…</li>
<li>It is much easier to get help and find resources for raw Android or iPhone development than for MonoX development.  Not trying to bash the Mono projects here, but most of mobile programming is spent googling for how to do things.  By sticking with C# you are really limiting yourself in terms of finding answers.</li>
<li>Change and learning different things is good.  I’m not sure you can fully appreciate the design of a framework or platform unless you develop against it the way it was designed.  I could be wrong, but I think there is a potential “lost in translation” problem in using C# on the iPhone or Android platforms.</li>
</ol>
<p>After I learn iPhone development, I might try MonoTouch and see if it makes my life easier, but I need a good baseline first.</p>
<p>Well, I’m off on my journey.  Going to head on to the back of the wardrobe in the “Spare-Oom.”  I have to meet Mr. Tumnus, we are having tea with Mr. Wozniak and Mr. Jobs.</p>
<p><a href="http://complextosimple.files.wordpress.com/2011/02/mrtumnus.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="mrtumnus" src="http://complextosimple.files.wordpress.com/2011/02/mrtumnus_thumb.jpg?w=462&#038;h=478" border="0" alt="mrtumnus" width="462" height="478" /></a></p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1244/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1244/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1244/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1244&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2011/02/01/objective-c-here-i-come/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/02/iphone_thumb.jpg" medium="image">
			<media:title type="html">iphone</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2011/02/mrtumnus_thumb.jpg" medium="image">
			<media:title type="html">mrtumnus</media:title>
		</media:content>
	</item>
		<item>
		<title>Book Review: Pro Android 2</title>
		<link>http://simpleprogrammer.com/2010/09/07/book-review-pro-android-2/</link>
		<comments>http://simpleprogrammer.com/2010/09/07/book-review-pro-android-2/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 14:58:17 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Book Review]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1085</guid>
		<description><![CDATA[I recently completed reading Pro Android 2. It is a pretty large book, so it took me awhile, but I finally got through it. I hadn&#8217;t really read any other Android books, so I don&#8217;t know how it compares. The book goes through creating an Android application using Eclipse. It contains many source code examples [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1085&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently completed reading <a href="http://www.amazon.com/gp/product/1430226595?ie=UTF8&amp;tag=makithecompsi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1430226595">Pro Android 2</a>. It is a pretty large book, so it took me awhile, but I finally got through it. I hadn&#8217;t really read any other Android books, so I don&#8217;t know how it compares.</p>
<p><a href="http://complextosimple.files.wordpress.com/2010/09/proandroid2.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="proandroid2" src="http://complextosimple.files.wordpress.com/2010/09/proandroid2_thumb.jpg?w=471&#038;h=471" border="0" alt="proandroid2" width="471" height="471" /></a></p>
<p>The book goes through creating an Android application using Eclipse. It contains many source code examples that are very complete. The book really seems to be focused more on getting going vs going in-depth with the APIs.</p>
<p><strong>The good:</strong></p>
<ul>
<li>Great jump start diving right into Android development without wasting much time.</li>
<li>Very complete examples that can get you going and can be modified for your own application.</li>
<li>Balances basic examples with more complex architectural constructs well. There is a good mix of examples that build on basic concepts and show how to implement more of an MVP style of development.</li>
<li>Covers a pretty wide breadth of the Android platform, which makes it easy to know what exactly is capable.</li>
</ul>
<p><strong>The bad:</strong></p>
<ul>
<li>Although the beginning of the book was very interesting and informative, some of the chapters seemed to drag on.</li>
<li>A whole huge chapter devoted to search.  Search is not something that most applications would need to make use of.</li>
<li>A whole huge chapter on 3d application development.  Not something I felt should have been in the book.  Pretty boring and actually really scary.  I don’t think I’ll ever develop a 3d application for Android.</li>
</ul>
<p><strong>What I learned:</strong></p>
<p>I had already started building my Android application before reading this book, so not very much of it was completely new to me, but I definitely learned some things from the book.</p>
<p>I was really surprised to see how easy 2D animation is with Android.  The book does a good job of explaining it and providing examples.  I feel like I could very easily implement 2D animation after reading this book.</p>
<p>I learned about  to create and use content providers.  This aspect of Android development is a bit tricky, but I felt like Pro Android 2 did a good job of explaining it and providing examples that I would be able to use.</p>
<p>I also learned to create a home screen widget.  The examples in the book were really good and provided a complete usable implementation that could be easily used as a base for creating your own.</p>
<p>Towards the end of the book, <a href="http://www.appcelerator.com/">Titanium Mobile</a> is mentioned.  Titanium Mobile is a WebKit-based native application development framework which allows developers to write applications that target multiple platforms.  It looks really cool, and I kind of wish that was the first chapter in the book, so that I could have explored that before getting so far into actual Android development.</p>
<p>Overall, I would definitely recommend the book.  I feel pretty confident that someone with no Android experience should be able to pick up that book and get going with their first application.  I definitely learned some things the hard way, before I read the book.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1085/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1085/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1085/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1085&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2010/09/07/book-review-pro-android-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2010/09/proandroid2_thumb.jpg" medium="image">
			<media:title type="html">proandroid2</media:title>
		</media:content>
	</item>
		<item>
		<title>Android Presenter To Activity Using Guice</title>
		<link>http://simpleprogrammer.com/2010/08/19/android-presenter-to-activity-using-guice/</link>
		<comments>http://simpleprogrammer.com/2010/08/19/android-presenter-to-activity-using-guice/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 14:12:47 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1058</guid>
		<description><![CDATA[In a prior post I talked about how to unit test android applications.  I made some references to wiring up an Activity with a presenter, but I didn’t really show how I was doing that. I got some requests to show some sample code, so I thought I would explain what I was doing here [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1058&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a prior post I talked about how to <a href="http://simpleprogrammer.com/2010/07/29/the-best-way-to-unit-test-in-android-part-2/">unit test android applications</a>.  I made some references to wiring up an Activity with a presenter, but I didn’t really show how I was doing that.</p>
<p>I got some requests to show some sample code, so I thought I would explain what I was doing here and see if anyone had better suggestions.</p>
<h2>Roboguice</h2>
<p>To make it easier to unit test and to decouple my system as much as possible, I am using a dependency injection framework called <a href="http://code.google.com/p/roboguice/">Roboguice</a>.  It is basically the Google Guice framework that is ported to Android and adds some Android specific functionality.</p>
<p>One challenge you will most likely first encounter when working with Roboguice is that a presenter is going to need a reference to the Activity class that is going to represent its view.  Since the Activity class has to create the presenter, this presents a dependency injection challenge.</p>
<p>We can’t just ask for a presenter from our container and have it auto-resolve the dependency on the Activity.  (That is we can’t rely on constructor injection in this case.)</p>
<h2>Setter injection to the rescue</h2>
<p>One thing we can do, is use setter injection instead of constructor injection to inject the other references our presenter will need.</p>
<p>Guice provides us with an easy way to perform setter injection after we have created the object.  I use this technique to make sure that I can pass my activity into the presenter and still have the benefits of having the other dependencies injected into the presenter.</p>
<p>Here is some code showing my OnCreate method inside my activity.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:645a8872-29d7-40ea-8885-908045ec5e99" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java; pad-line-numbers: true;">
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.pacemaker);

    this.presenter = new MainPresenter(this);
    Injector injector = Guice.createInjector(new PaceMakerModule());
    injector.injectMembers(presenter);
}
</pre></p>
</div>
<p>This code is creating an instance of my presenter which holds a reference to the Activity, or view, it is manipulating.  Then Guice injects dependencies using the module I created into any properties that are annotated with @Inject.</p>
<p>Here is what some of those presenter set methods look like:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:47584bf9-8a03-4a4b-8ce9-29770c06b6bb" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
@Inject
public void setSystemClock(ISystemClock systemClock)
{
     this.systemClock = systemClock;
}

@Inject
public void setRunSerializer(IRunSerializer serializer)
{
     this.runSerializer = serializer;
}
</pre></p>
</div>
<p>You can see that they are declared in the module like so:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:3cb551b5-a302-4613-adf5-4217e27bba75" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java;">
public class PaceMakerModule extends AbstractAndroidModule
{
   @Override
   protected void configure()
   {
	bind(ISystemClock.class).to(SystemClockWrapper.class);
	bind(IRunSerializer.class).to(GPXRunSerializer.class);
    }

}
</pre></p>
</div>
<p>It’s not exactly pretty, but Android applications are really a loosely coupled sets of Activities which are the entry point into your code.  It makes it very difficult to create a MVP type of framework that we might be used to.</p>
<p>If you know of a better way than what I am doing please let me know, and if you have any questions or suggestion, I’m always glad to hear them or help if I can.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1058/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1058/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1058/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1058&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2010/08/19/android-presenter-to-activity-using-guice/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>
	</item>
		<item>
		<title>The Best Way to Unit Test in Android: Part 2</title>
		<link>http://simpleprogrammer.com/2010/07/29/the-best-way-to-unit-test-in-android-part-2/</link>
		<comments>http://simpleprogrammer.com/2010/07/29/the-best-way-to-unit-test-in-android-part-2/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:34:35 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1027</guid>
		<description><![CDATA[In my last post I presented two choices for unit testing in Android. Unit test on the real device or emulator using the real android framework Unit test on our PC using the JVM Each choice has some pros and cons, but for me it came down to the speed and flexibility allowed by running [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1027&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my last post I presented two choices for unit testing in Android.</p>
<ul>
<li>Unit test on the real device or emulator using the real android framework</li>
<li>Unit test on our PC using the JVM</li>
</ul>
<p>Each choice has some pros and cons, but for me it came down to the speed and flexibility allowed by running in a real JVM.  I actually tried to create an Android unit testing project using the scaffolding provided by Google but it turned out to be very restrictive, especially since I couldn’t use JMock.</p>
<p>There is also something to be said for being able to execute the unit tests extremely quickly.  If you have to wait for an emulator to come up, or try to run them on a real device, it is less likely the unit tests will be run.</p>
<h2>How to do it</h2>
<p>The basic idea of this approach is fairly simple.</p>
<p>We are going to try and abstract away any Android specific calls from our application and then unit test the plain Java logic in the application just like we would any other Java project.</p>
<h4>Step 1:  Create a JUnit project</h4>
<p><strong></strong>Create a new JUnit project just like you would for unit testing any Java application.</p>
<p><a href="http://complextosimple.files.wordpress.com/2010/07/newjavaproject.png"><img style="display:inline;border-width:0;" title="NewJavaProject" src="http://complextosimple.files.wordpress.com/2010/07/newjavaproject_thumb.png?w=498&#038;h=477" border="0" alt="NewJavaProject" width="498" height="477" /></a></p>
<p>Make sure you chose <strong>Java Project</strong> rather than <strong>Android Test Project.</strong></p>
<p>From here you can add your JUnit references to your build path.  <em>I would also recommend adding </em><a href="http://code.google.com/p/instinct/"><em>Instinct</em></a><em> for doing BDD style testing.  Instinct uses JMock internally to create mocks for you using a declarative approach.</em></p>
<p>The only other thing you will want to do with this project is to add the android.jar to the build path.  The android.jar can be found in your Android SDK directory under the platform directory that corresponds to the API version you are targeting with your application.</p>
<p>For example, on my machine, I am targeting Android 1.6, so my android.jar is at:  C:\Android\android-sdk-windows\platforms\android-4.</p>
<p>Now remember, you are including the android.jar in the project only so your classes can understand what types exist in the Android framework.  <strong>If you even try to call a constructor on a class in android.jar, you will get an exception.</strong></p>
<h4>Step 2: Pull all the code you can out of the Activity.</h4>
<p>The next thing we need to do is clean up our Activity class to make sure that it has the smallest amount of logic in it as possible.</p>
<p>Since we can’t actually instantiate any types that exist in the Android framework, we are not going to be able to create an instance of our Activity in the test project.  So we are not going to be able to unit test our Activity.  This isn’t a problem if most of the logic we care about testing exists in other layers in our system.</p>
<p>You can design the lower layers however you want.  I am still not quite sure the best approach here, but what I did was put a presentation layer directly below the Activity.  I have a Presenter class directly below the Activity that tells my activity what to do.  The Activity passes on any interesting events or information to the Presenter.</p>
<p>You should leave the Activity with the responsibility of setting the text on its own view objects, but create methods for your lower layers to tell the Activity what text to set the objects to and so forth.  Activity is going to act as an adapter to a large portion of the Android framework for your application.</p>
<p>Because the entrance point into your application is going to be the Activity, you will need to wire up the rest of your layers from the Activity.  This is a little strange, but it works.  In my application, I create a new Presenter and pass <em>this </em>into it on the constructor.</p>
<p>When you are done, your Activity should look pretty thin.  It should delegate all its event handler logic down to the lower layers and act as a pass through for manipulating the view.</p>
<h4>Step 3: Wrap remaining Android object calls.</h4>
<p>You&#8217;re going to find that some of the remaining Android API will need to be called from lower down than the Activity.  This is not as big of a problem as it seems.</p>
<p>In my application I needed to make some calls to android.os.SystemClock.  I needed to make those calls lower down than the activity because it is part of the heart of the logic of my application.</p>
<p>I created a simple SystemClockWrapper class that wraps system clock and delegates any calls to the real SystemClock class.  Then I extracted an interface from that class called ISystemClock (hey, I like the C# convention for interfaces.)</p>
<p>Finally, in my application logic, I allowed the ISystemClock reference to be passed in or “injected” through the constructor of the class that used it.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:e333f287-e382-4a5e-8493-b182750f180f" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: java; pad-line-numbers: true;">
public class SystemClockWrapper implements ISystemClock
{
     public long getElapsedRealTime()
     {
          return SystemClock.elapsedRealtime();
     }

}

public interface ISystemClock
{
     public abstract long getElapsedRealTime();

}

</pre></p>
</div>
<p>In my unit test I just pass in a mock version of the ISystemClock interface.</p>
<p>One hint here is to use the refactor tool in your IDE to extract an interface.  This can save you some time of trying to manually create interfaces for large pieces of functionality you are wrapping.</p>
<h2>Putting it all together</h2>
<p>Now you should be able to create your unit tests against most of your application logic and run them just like any other unit test project.</p>
<p>The only thing you won’t be able to do is unit test the logic in your Activity classes.  This shouldn’t be much of a problem if you have made them into views, because they should only contain view logic.</p>
<p>If you really want to be able to write some tests for the Activity though, you can create another actual <em>Android Test Project </em>and use Google’s framework to write unit tests from there.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1027/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1027/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1027/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1027&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2010/07/29/the-best-way-to-unit-test-in-android-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2010/07/newjavaproject_thumb.png" medium="image">
			<media:title type="html">NewJavaProject</media:title>
		</media:content>
	</item>
		<item>
		<title>The Best Way to Unit Test in Android: Part 1</title>
		<link>http://simpleprogrammer.com/2010/07/27/the-best-way-to-unit-test-in-android/</link>
		<comments>http://simpleprogrammer.com/2010/07/27/the-best-way-to-unit-test-in-android/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:58:14 +0000</pubDate>
		<dc:creator>jsonmez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">https://complextosimple.wordpress.com/?p=1018</guid>
		<description><![CDATA[I’ve been doing some development in Android lately on a top secret project, one that hopefully will change the way you run with your phone. In the course of building this app, in a previous post I mentioned that I wanted to find the right, or perfect way, to build an Android application. I haven’t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1018&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been doing some development in Android lately on a top secret project, one that hopefully will change the way you run with your phone.</p>
<p>In the course of building this app, in <a href="http://simpleprogrammer.com/2010/07/20/the-hardest-thing-i-struggle-with/">a previous post</a> I mentioned that I wanted to find the right, or perfect way, to build an Android application.</p>
<p>I haven’t found the best way to build an Android application into a nice clean design pattern, but have found a way that seems to work, and makes the application testable and easy to maintain.</p>
<p>I do believe though, that I have found the optimal way to do unit testing in Android right now.  Yes, a bold statement, but I have looked high and low for a better solution, and can’t find one.</p>
<p><a href="http://complextosimple.files.wordpress.com/2010/07/htcandroid.png"><img style="display:inline;border:0;" title="HTC-Android" src="http://complextosimple.files.wordpress.com/2010/07/htcandroid_thumb.png?w=455&#038;h=342" border="0" alt="HTC-Android" width="455" height="342" /></a></p>
<h2>The problems</h2>
<p>So first a little bit of background on the problem with unit testing in Android.  Take what I say with a grain of salt here, because I am not an Android platform expert, and feel free to correct me if I misstate something.</p>
<h4>Android.jar</h4>
<p>If you download the Android SDK from google, you will find that the android.jar you get with the SDK is much like a C++ header file; it doesn’t actually contain any working code.  As a matter of fact, all the methods are stubbed out to throw an exception with the message “Stub!” when you call them.  How cute.</p>
<p>The real android.jar implementations live on the emulator, or your real Android device.  So, if you want to actually run any code that is going to call any methods or try to construct real Android framework classes, <strong>you must run that code inside the emulator or a real device.</strong></p>
<h4><strong>Dalvik VM</strong></h4>
<p>When you&#8217;re working with Android, it sure feels like you are writing regular old standard Java SE code, <strong>but you are not. </strong>You probably won’t notice the difference, as almost everything that you need is there in the Dalvik VM implementation of Java.</p>
<p>Dalvik is not even a Java Virtual Machine at all.  That is right, it runs on cross-complied .class files which are converted to a .dex format.  <strong>Yes, is does not use java byte code.</strong></p>
<p>Why do I mention all this?  Because you might want to use something like JMock to mock your dependencies when writing your unit tests.</p>
<p>Well, you can’t.  It just isn’t going to work, because the Dalvik VM doesn’t use java byte code, so the reflective coolness that mocking frameworks like JMock use doesn’t work the same.</p>
<p>Be aware that any external library you try to use in your Android project may not work because Android does not support the full Java SE implementation.  It actually is a subset of the <a href="http://en.wikipedia.org/wiki/Apache_Harmony">Apache Harmony</a> Java implementation.</p>
<h4>There is no main()</h4>
<p>Where does an Android application start running?  From the activity.  Which is basically the view.  (Some people will argue this is the controller or presenter.  And yes, I agree in respect to the Android framework it is, but in regard to your application framework it is the view.)</p>
<p>Android applications define a starting activity and launch from there.  Activities can even be launched from other applications.</p>
<p>This tends to disrupt most of our MVC, MVP, MVVP pattern architectures, as the view is going to be the entry point and will have to be responsible for initializing the rest of the application.  (That is not entirely true, as there is an android.app.Application class that gets called the first time your app is run, to launch the main activity, but for the most part you can’t do much here.)</p>
<p>Essentially though, you have to build your architecture based on each Activity being its own separate little application, with the entry point being in the activity.  This puts some serious constraints on unit testing.</p>
<h2>Putting it all together</h2>
<p>So if I can sum up the problems briefly, I would say:</p>
<ul>
<li>Android framework code has to run in the emulator or on a device.</li>
<li>Dalvik VM doesn’t allow us to use our standard mocking frameworks.</li>
<li>Entry points for our applications are in the views.</li>
</ul>
<p>The first problem, combined with the second, lead us to an interesting choice.  Should we run our unit tests on an actual emulator or device using the Dalvik VM, or should we run them in a JVM?</p>
<p>It is probably not an obvious question, but let me explain why it is the most relevant.</p>
<p>In writing an application, we are going to have application logic that has nothing specifically to do with the Android platform, and we are going to have Android platform specific logic (drawing views, handling Android OS events, interacting with Android APIs etc.)</p>
<p>If we want to write true unit tests, we need to isolate our classes and test them individually.  We should be able to do this for our application logic, without relying on the Android framework.  If we don’t rely on the Android framework, we don’t need to run on a real or emulated device, thus we are not constrained to the Dalvik VM.</p>
<p><strong>If we choose to run our unit test code on a real or emulated device:</strong></p>
<ul>
<li>We will be able to use the Android framework APIs in our testing efforts.  For example, we can create new location objects instead of mocking them up.</li>
<li>We will be completely true to the real execution of our code.  Since we will be using the real VM the code will run on.</li>
<li>Since we are running our tests on a device or emulator, they will run much slower.</li>
<li>We won’t be able to use <a href="http://www.jmock.org/">JMock</a>, EasyMock, or Mockito, we’ll either have to roll our own mocks or use a fledgling Android mocking framework.</li>
</ul>
<p><strong>If we chose to run our unit test code in a JVM on our PC:</strong></p>
<ul>
<li>We will have the full power of the JVM available to our test code, so we can use mocking frameworks like JMock, and BDD frameworks like <a href="http://code.google.com/p/instinct/">Instinct</a>.</li>
<li>We will run our unit tests much faster, since they will be using our PC instead of a device.</li>
<li>We can use standard unit testing practices and not have to inherit from special Android classes, or use special Android test runners.</li>
<li>We will have to wrap any calls to the actual Android framework if we need to use any Android classes or services deeper down in our application.</li>
<li>We have a small risk of having different behavior between running the tests and the real application, because we will be running the code on different VMs.</li>
</ul>
<p>In my next post, I’ll detail which option I chose and why and also give some detailed steps of how to get setup and running.</p>
<h6>As always, you can subscribe to this <a href="http://feeds.feedburner.com/MakingTheComplexSimple">RSS feed</a> to follow my posts on Making the Complex Simple.  Feel free to check out <a href="http://elegantcode.com/">ElegantCode.com</a> where I post about the topic of writing elegant code about once a week.  Also, you can follow me on twitter <a href="http://twitter.com/jsonmez">here</a>.</h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/complextosimple.wordpress.com/1018/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/complextosimple.wordpress.com/1018/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/complextosimple.wordpress.com/1018/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=simpleprogrammer.com&amp;blog=10597120&amp;post=1018&amp;subd=complextosimple&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://simpleprogrammer.com/2010/07/27/the-best-way-to-unit-test-in-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/695e2a956b2dcb5ac45a7095b6ee338a?s=96&#38;d=retro&#38;r=PG" medium="image">
			<media:title type="html">jsonmez</media:title>
		</media:content>

		<media:content url="http://complextosimple.files.wordpress.com/2010/07/htcandroid_thumb.png" medium="image">
			<media:title type="html">HTC-Android</media:title>
		</media:content>
	</item>
	</channel>
</rss>
