<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;AkUHQX48eip7ImA9WhRaE0U.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073</id><updated>2012-02-16T02:30:30.072-08:00</updated><category term="assert failed" /><category term="c2dm" /><category term="command line tools" /><category term="threads" /><category term="sms" /><category term="enterprise mobility" /><category term="security" /><category term="apple" /><category term="development" /><category term="gingerbread" /><category term="doInBackground" /><category term="device management" /><category term="intellij" /><category term="GRI40" /><category term="service" /><category term="IDE" /><category term="mobility" /><category term="honeycomb" /><category term="handler" /><category term="encryption" /><category term="AsyncTask" /><category term="android" /><category term="UI thread" /><category term="blackberry" /><category term="commands" /><category term="wp7" /><category term="push" /><category term="nokia" /><category term="mobile development" /><category term="handlerthread" /><category term="emulator" /><category term="comparison" /><category term="looper" /><category term="application management" /><category term="2.3.3" /><category term="status 7" /><category term="Main Thread" /><category term="background task" /><category term="IntentService" /><category term="message passing" /><category term="geo fix" /><category term="installation aborted" /><title>AdvanTej</title><subtitle type="html">With Android, I have an Intent to do everything !</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://techtej.blogspot.com/" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/TechTej" /><feedburner:info uri="techtej" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>TechTej</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;C0YHR3w8cSp7ImA9WhZUFkU.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-3334896654537136660</id><published>2011-06-09T21:45:00.000-07:00</published><updated>2011-06-09T21:45:36.279-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-09T21:45:36.279-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="application management" /><category scheme="http://www.blogger.com/atom/ns#" term="security" /><category scheme="http://www.blogger.com/atom/ns#" term="device management" /><category scheme="http://www.blogger.com/atom/ns#" term="enterprise mobility" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Enterprise mobility and Android</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Its quite some time after the GoogleIO. Have been busy digesting some info and thinking a lot. Just a day before IO, I wrote some of &lt;a href="http://techtej.blogspot.com/2011/05/understanding-enterprise-mobility.html"&gt;my thoughts on Enterprise mobility.&lt;/a&gt; Today, I'll try and visit certain aspects in detail as well as try to list what Android has to offer as of now.&lt;br /&gt;
&lt;br /&gt;
Now, from current trends in market and from my understanding till date, I see the current enterprise mobility having 3 components as follows :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/--O6ffQslbmQ/TfGQ9R-7fMI/AAAAAAAADl0/Z_m62wHJk1k/s1600/Screen+shot+2011-06-09+at+11.25.45+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://3.bp.blogspot.com/--O6ffQslbmQ/TfGQ9R-7fMI/AAAAAAAADl0/Z_m62wHJk1k/s640/Screen+shot+2011-06-09+at+11.25.45+PM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;1. Device Management&lt;br /&gt;
2.&amp;nbsp;Security&lt;br /&gt;
3.&amp;nbsp;Application management&lt;br /&gt;
&lt;br /&gt;
Enterprises looking for a complete mobility solution are mostly looking at these three areas. I'll try to briefly touch on each of these and discuss what Android has to offer (and not offer) to enterprise mobility. [For clear separation, I have marked Android Specific details in &lt;span class="Apple-style-span" style="color: #0b5394;"&gt;BLUE&lt;/span&gt;&amp;nbsp;: I know Green (&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: x-small; line-height: 15px;"&gt;#A4C639&lt;/span&gt;) would have been appropriate, but I didn't think it was good for reading :)]&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;1. Device Management :&lt;/u&gt;&lt;/b&gt;&amp;nbsp; Device management (DM) mainly deals with being able to remotely alter certain aspects of the devices. Again, I see DM being split into the following.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/-or-x41FdR_U/TfGQ9m7C3TI/AAAAAAAADl4/-abSqWG5N_o/s1600/Screen+shot+2011-06-09+at+11.25.57+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="223" src="http://3.bp.blogspot.com/-or-x41FdR_U/TfGQ9m7C3TI/AAAAAAAADl4/-abSqWG5N_o/s320/Screen+shot+2011-06-09+at+11.25.57+PM.png" style="cursor: move;" width="320" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;i. Provisioning&lt;/i&gt; deals with mass deployment of various settings on large number of handsets. &amp;nbsp;For instance, provisioning the devices with corporate WiFi information, VPN access parameters and configuration of email settings etc... For the IT department, being able to provision these settings is beneficial since it helps them carry out the tedious task as well as reduces chances of human error and avoid complex email instructions.&lt;br /&gt;
&lt;br /&gt;
Blackberry and iOS have most of the DM functions baked into the platform. This means, one can configure a DM server (may require manual steps). Once configured, the DM server can send commands to the device which will be understood by the device platform and reacted accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Android, however, requires an on-device management agent (aka Device administrator) which should implement the Device Admin APIs (Android 2.2 onwards) in order to&amp;nbsp;perform any of the DM functions. Furthermore,&amp;nbsp;&amp;nbsp;Android doesn't support provisioning out of the box.&amp;nbsp;Rather of all the top IT demands (WiFi, VPN, Exchange etc...), only WiFi can be configured programmatically by the on-device agent.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;i&gt;ii. Device Control&lt;/i&gt; deals with&amp;nbsp;being able to remotely take certain actions on the device that may affect the end user. E.g. device lock, unlock, wipe, set/reset password.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;With the device admin software installed, Android can do these basic device control functions like device wipe, lock/unlock and set/reset password.&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;There is however one way to achieve device control functions without having to install any device admin. The trick here is that most Android devices ship with a Email application which can be configured with Exchange information. By default Exchange uses the ActiveSync protocol for syncing mails. Of lately (I guess Android 2.2 onwards), I have seen that while configuring Exchange, the platform shows the standard Device Management screen asking for adding the Exchange as a device admin. If you do this, then by configuring the Email, you can execute device control commands like lock/unlock, set/reset password, wipe etc... To check this go to Settings -&amp;gt; Location and Security -&amp;gt; Select Device administrators. You should be able to see Email application being listed if you have configured Exchange (ActiveSync ).&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;i&gt;iii. Device Policies :&lt;/i&gt;&amp;nbsp;Policies allow enterprises to control certain settings of the device. This is different from provisioning in that policies can be considered as '&lt;b&gt;enforced&lt;/b&gt;' settings. While someone may change the provisioned settings, device policies are not "meant" to be changed. On Blackberry and to some extent the iOS, the platform restricts the user from changing any policies set by the IT administrator. These policies may include restrictions on the browser to disable javascript, avoid using the phone as USB storage device, disabling camera, etc...&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Again, in the case of Android, you will need the on-device admin app to control (only) a subset of what the IT demands traditionally. Basic policies like enforcing a device password, password quality etc.. are supported out of the box with the Device admin APIs.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;b&gt;&lt;u&gt;2. Security :&lt;/u&gt; &lt;/b&gt;By far, this is THE feature enterprises cannot live without. When enterprises allow data to be accessed remotely, its security is of prime importance. There are 3 components related to security that I visualize as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://3.bp.blogspot.com/-YkFSlkgeHyI/TfGQ-ahHPdI/AAAAAAAADl8/nnek21aJFVg/s1600/Screen+shot+2011-06-09+at+11.26.30+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="181" src="http://3.bp.blogspot.com/-YkFSlkgeHyI/TfGQ-ahHPdI/AAAAAAAADl8/nnek21aJFVg/s320/Screen+shot+2011-06-09+at+11.26.30+PM.png" style="cursor: move;" width="320" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;i. Encryption :&lt;/i&gt; Any data that is stored by any application as well as any data that is communicated to and from the device, needs to be encrypted.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;Android apps can use SSL tunnels through with data can be transported. However, the data stored on the device (phone memory and SD) is&amp;nbsp;up to&amp;nbsp;the applications. Prior to honeycomb (Android 3.0) there is no support for turning on encryption on the device. Even with Honeycomb, a device administrator application can request for the encryption process to begin, and it will start the encryption ONLY IF it is supported by the device on which the agent is running. Things are still pretty unclear about the way encryption is supported (hardware vs software etc...). One of &lt;a href="http://techtej.blogspot.com/2011/02/android-30-encryption-initial-thoughts.html"&gt;my previous posts&lt;/a&gt; raises these issues. I'll update both the blog posts once enough information is available.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;ii. Device Policies :&lt;/i&gt;&amp;nbsp;I have purposefully included policies again under Security.&amp;nbsp;I think this link is important to note.&amp;nbsp;This is just to remind that policies are restrictive settings enforced in order to avoid security compromise.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;iii. Compliance :&lt;/i&gt; Now, we have policies in place. And as I said these need to be enforced on the device. However, it may happen that the user knowingly or unknowingly changes some setting that violates certain policy (that cannot be technically enforced on the device - technology limitation). This may put corporate data at risk. It is important for the IT to determine such instances. This leads to constantly monitoring the device and making sure that it is "in compliance" with the policies.&lt;br /&gt;
Usually, compliance checking may be done on the server that monitors the device. This can be achieved by querying the device for certain parameters periodically and then running the compliance rules against the values received. These rules usually test whether the device adheres to all the policies, if not then the resulting actions could be anything from blocking corporate access for that device to wiping the device. This totally depends on the IT policies for the enterprise.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;The device admin app can play the role of reporting parameter values to the DM server. To monitor Android for certain metrics, the server can implement the Google C2DM (cloud to device messaging discussed in this blog post) to send query messages to a device admin app which can reply back.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;3. Application Management :&lt;/b&gt;&lt;/u&gt;&amp;nbsp;One of the basic goals for enterprises is to mobilize the business. As a result, enterprises have started mobilizing many internal applications. So, as a part of enterprise mobility, the IT also has to manage the mobile apps. Application management (AM) can be again viewed as having the two main functions :&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-sJ3YxXyfzi0/TfGQ-uyVKlI/AAAAAAAADmA/KspR_PV2sGY/s1600/Screen+shot+2011-06-09+at+11.26.45+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="226" src="http://2.bp.blogspot.com/-sJ3YxXyfzi0/TfGQ-uyVKlI/AAAAAAAADmA/KspR_PV2sGY/s320/Screen+shot+2011-06-09+at+11.26.45+PM.png" width="320" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;i. Monitor/Debug apps :&lt;/i&gt; Since most of the applications may be internal apps, the development and testing phase becomes critical. Also, since these apps may directly affect employee productivity, debugging these apps during development and after deployment is crucial too. One of the tasks of AM is to help the development and debugging process easier. Once the app is in production, AM can help monitor the status of apps and surface any problems earlier. Monitoring of apps may also refer to getting an apps inventory and determining "blacklisted" apps from security point of view. This may tie back to compliance.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;ii. Deploy / Remove apps :&lt;/i&gt;&amp;nbsp;With many such applications there is a demand for Enterprise application catalog on which apps would be listed and shown/accessed depending on the role of the employee. Since these apps may contain critical corporate information, it is important for the IT to be able to control these apps remotely. Being able to install, remove these apps is one of the most popular demands from IT.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #0b5394;"&gt;With Android, anyone can "sideload" an application. This means all the application&amp;nbsp;(apk)&amp;nbsp;files can be accessed via a webpage. However, there are few points to note. In order to install any application that is not listed in the Android Market (consumer app), one has to enable a setting called applications from an "Unknown Source". While doing so, the user gets a dreaded message that may scare him off. Also, it is worth noting that there is currently no official way to push the application on the device and install/uninstall it without the user intervention. If you already have your device admin agent on the device, then it can download the app binary and trigger the install process or trigger the uninstall process of an existing app which will redirect the user to the install/uninstall approval screen. There are some app markets (like AppBrian) which have (with limited capabilities) "managed" to remotely push and install applications on Android phones. However, there is no official way to do so.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, here is a complete picture of how I see Enterprise mobility as of now:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-iXQ2o-Zy320/TfGQ-27MJcI/AAAAAAAADmE/vsp9GIDSjww/s1600/Screen+shot+2011-06-09+at+11.29.46+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="283" src="http://4.bp.blogspot.com/-iXQ2o-Zy320/TfGQ-27MJcI/AAAAAAAADmE/vsp9GIDSjww/s640/Screen+shot+2011-06-09+at+11.29.46+PM.png" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
To summarize, Android really doesn't have much to offer at this moment apart from few Device Admin APIs and Encryption (hardware dependent - 3.0 onwards). With the growing demand for Android and the changing trend of Employee liable devices, it certainly is a challenge for IT. The Google enterprise team unfortunately didn't seem to address most of these issues and didn't seem open to a lot of questions posed at the GoogleIO. The talk at GoogleIO can be found here : (&lt;a href="http://www.google.com/events/io/2011/sessions/taking-android-to-work.html"&gt;http://www.google.com/events/io/2011/sessions/taking-android-to-work.html&lt;/a&gt;) I hope they have some plan for the Enterprise mobility because the wave has just begun.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-3334896654537136660?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yIXRrMt0AnygSGkyF_WbGGW8lm8/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yIXRrMt0AnygSGkyF_WbGGW8lm8/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yIXRrMt0AnygSGkyF_WbGGW8lm8/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yIXRrMt0AnygSGkyF_WbGGW8lm8/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/sBYzraMZ2Ek" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/3334896654537136660/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/06/enterprise-mobility-and-android.html#comment-form" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3334896654537136660?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3334896654537136660?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/sBYzraMZ2Ek/enterprise-mobility-and-android.html" title="Enterprise mobility and Android" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/--O6ffQslbmQ/TfGQ9R-7fMI/AAAAAAAADl0/Z_m62wHJk1k/s72-c/Screen+shot+2011-06-09+at+11.25.45+PM.png" height="72" width="72" /><thr:total>6</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/06/enterprise-mobility-and-android.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQHRng6eCp7ImA9WhZXGUs.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-9118251673295963671</id><published>2011-05-09T11:55:00.000-07:00</published><updated>2011-05-09T11:55:37.610-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-05-09T11:55:37.610-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="blackberry" /><category scheme="http://www.blogger.com/atom/ns#" term="security" /><category scheme="http://www.blogger.com/atom/ns#" term="mobility" /><category scheme="http://www.blogger.com/atom/ns#" term="enterprise mobility" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="apple" /><title>Understanding Enterprise Mobility</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[I'm sitting at a Starbucks waiting for the GoogleIO registration to open up. There is an interesting session 'Taking Android to work' which I'll be attending. Google's approach to enterprise mobility seems to be different than Blackberry or Apple : they don't have anything baked into the platform. The GoogleIO session will hopefully provide more insights into the future path. If you are an attendee and interested in this topic, I would definitely love to have a chat with you. You can follow me on Twitter : @advantej ]&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
For the past few months, I'm trying to understand the enterprise mobility space. It had kind of existed in the past but emerging again with a new face altogether. Its definitely a larger wave than the earlier one.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A look into the past:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Laptops introduced mobility into enterprise. There were cell phones before, but those weren't 'smart' enough. Their primary purpose was just to carry out conversations. Laptops made it possible to take the work with you. There was also a short period that showcased Personal Digital&amp;nbsp;Assistants&amp;nbsp;(PDAs) which were rather bulky to carry around and capabilities mostly limited to managing your schedule, taking notes and some basic messaging. But the&amp;nbsp;truly workable mobile devices were laptops.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Enterprise Viewpoints: Two sides of a coin&lt;/b&gt;&lt;br /&gt;
&lt;u&gt;The Good:&lt;/u&gt;&lt;br /&gt;
For enterprises, mobility means a lot. It is a means of growing&amp;nbsp;business, capturing opportunities and bringing back information, knowledge, keeping the organization going on, no matter where the people in the organization are. Be it the CEO, CTO, marketing or sales people or any other&amp;nbsp;management&amp;nbsp;folks or your awesome engineers: mobility builds the necessary bridges whenever it matters to&amp;nbsp;achieve&amp;nbsp;the required goals.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;The Worrisome:&lt;/u&gt;&lt;br /&gt;
However, practically this means accessing company resources from devices and environments on which enterprises may not have any control. While mobility helps enterprises grow the concern about information security in uncontrolled environments makes enterprises take a step back.&lt;br /&gt;
&lt;br /&gt;
In the laptop/PDA wave, managing devices was pretty much conventional. There was nothing new to do at least for the laptops because they had to deal with the same operating systems on laptops for which IT management was already being used for a long time.&lt;br /&gt;
&lt;br /&gt;
For pretty much long time, &lt;a href="http://www.rim.com/index.shtml"&gt;RIM&lt;/a&gt; provided enterprises with a solution to control the Blackberry mobile devices, enabling them to configure, manage and enforce policies on the devices.&lt;br /&gt;
&lt;br /&gt;
With &lt;a href="http://www.apple.com/"&gt;Apple&lt;/a&gt; and &lt;a href="http://developer.android.com/"&gt;Android&lt;/a&gt; powered devices entering the consumer market with different form factors, mobility has a new face. Not just that there are a lot of devices from different vendors and operating systems, its the fact that employees are consumers first. They are pretty much demanding the use of devices of their choice for accessing enterprise resources. Moreover, people don't like to carry multiple devices : a personal device and a company owned device. They want it there - all in one.&lt;br /&gt;
&lt;br /&gt;
The challenge for the IT is to support multiple mobile devices ensuring safety and security of enterprise resources. Apart from security which is central to enterprise mobility, IT demands being able to configure devices no matter what OS its running.&lt;br /&gt;
&lt;br /&gt;
Being a newbie to this space, I think of a lot of questions that I'm trying to answer. With many enterprise applications emerging, is enterprise mobility management limited to managing just the devices ? What about the applications ?&amp;nbsp;Do we need to control and analyse those too ? With employee owned devices is it acceptable to enforce enterprise policies all the time ? Some policies require control over the hardware as well. In my &lt;a href="http://ebiquity.umbc.edu/event/html/id/353/Collaborative-Data-Gathering-using-Context-aware-Mobile-Devices"&gt;masters thesis&lt;/a&gt;, I explored context awareness frameworks for mobile devices and prototyped one. I was wondering if it makes sense to exploit user context for enterprise policies. This may help in selectively applying policies depending on user context. This may help develop a win-win situation where employees don't feel controlled all the time but would be able to access the required resources. (For curious reader : &lt;a href="http://ebiquity.umbc.edu/project/html/id/92/Platys-From-Position-to-Place-in-Next-Generation-Networks"&gt;here&lt;/a&gt; is an interesting academic research project trying to identify high level contextual aspects for a mobile user.)&lt;br /&gt;
&lt;br /&gt;
Have got these questions and many more.... but one thing for sure - this wave is very large, unavoidable, with a lot of challenges and comes with competitive problems for the architects and engineers to solve.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[Thank you Starbucks for the internet !]&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-9118251673295963671?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A4M-RZ0v6ix9BaZPb6Ee8M72rQ4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A4M-RZ0v6ix9BaZPb6Ee8M72rQ4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A4M-RZ0v6ix9BaZPb6Ee8M72rQ4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A4M-RZ0v6ix9BaZPb6Ee8M72rQ4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/WhJKfMOfPTo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/9118251673295963671/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/05/understanding-enterprise-mobility.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/9118251673295963671?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/9118251673295963671?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/WhJKfMOfPTo/understanding-enterprise-mobility.html" title="Understanding Enterprise Mobility" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>0</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/05/understanding-enterprise-mobility.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C08MR3w_eyp7ImA9WhZSFk0.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-3870318216526378624</id><published>2011-03-31T11:54:00.000-07:00</published><updated>2011-03-31T13:04:46.243-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-31T13:04:46.243-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="service" /><category scheme="http://www.blogger.com/atom/ns#" term="Main Thread" /><category scheme="http://www.blogger.com/atom/ns#" term="comparison" /><category scheme="http://www.blogger.com/atom/ns#" term="UI thread" /><category scheme="http://www.blogger.com/atom/ns#" term="IntentService" /><category scheme="http://www.blogger.com/atom/ns#" term="looper" /><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="handler" /><category scheme="http://www.blogger.com/atom/ns#" term="background task" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="AsyncTask" /><title>Android Thread Constructs(Part 4): Comparisons</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this series of posts we have seen the following thread constructs:&lt;br /&gt;
1. Basic threads and communication between them [see &lt;a href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html"&gt;article&lt;/a&gt;]&lt;br /&gt;
2. Understanding the Main thread or the UI thread [see &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-1-ui.html"&gt;article&lt;/a&gt;]&lt;br /&gt;
3. IntentService [see &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-2-intent.html"&gt;article&lt;/a&gt;]&lt;br /&gt;
4. AsyncTask [see &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructs-part-3.html"&gt;article&lt;/a&gt;]&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NOTE:&lt;/b&gt; &amp;nbsp;These are Android specific constructs. Android also includes the java.util.concurrent package which can be&amp;nbsp;leveraged for concurrent tasks. That is out of the scope of my discussion.]&lt;br /&gt;
&lt;br /&gt;
So, when to use what ? What is the exact purpose of each ? What are the drawbacks of using one over the other ? Which one is easier to program ?&lt;br /&gt;
&lt;br /&gt;
I came across all these questions when trying to understand each of these. In due course of time, I have come up with some guidelines which I discuss in this post.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NOTE:&lt;/b&gt; Any of the recommendations made in this post and the table below are not comprehensive and final. There may be better and alternate ways of doing things. I would love to know any different views and get an insight into a different thought process. The views expressed in this post are my personal views.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Service&lt;/b&gt;&lt;br /&gt;
Before proceeding further, let me touch on the Service class. Traditionally speaking, the notion of service reminds us of task running in the background while we can work and interact with the UI. This causes confusion for newbies. Because in Android, even if the Service runs in the background, it runs on the Main Thread of the application. So, if at the same time if you have an activity displayed, the running service will take the main thread and the activity will seem slow. It is important to note that a Service is just a way of telling Android that something needs to run without a user interface in the background while the user may not interacting with your application. So, if you expect the user to be interacting with the application while the service is running and you have a long task to perform in a service, you need to create a worker thread in the Service to carry out the task.&lt;br /&gt;
So,&amp;nbsp;even if Service is not a threading construct, its a way of executing a task at hand. Hence I have included it in the comparison.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The table below tries to summarize various aspects of four task execution mechanisms : Service, Thread, IntentService, AsyncTask.&lt;/div&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Most of the points in the table are self-explanatory.&amp;nbsp;However, some points that need an&amp;nbsp;explanation are numbered and explained &amp;nbsp;below the table.&amp;nbsp;Also, this table is just to summarize about the concepts discussed in the previous posts. So, if anything is still unclear, I recommend to go through each individual posts in this series.&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;table border="1" cellpadding="2px" style="border-collapse: collapse; border-spacing: 0px;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th width="20%"&gt;&lt;br /&gt;
&lt;/th&gt;&lt;th width="20%"&gt;Service&lt;/th&gt;&lt;th width="20%"&gt;Thread&lt;/th&gt;&lt;th width="20%"&gt;IntentService&lt;/th&gt;&lt;th width="20%"&gt;AsyncTask&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;When to use ?&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Task with no UI, but shouldn't be too long. Use threads within service for long tasks.&lt;/td&gt;&lt;td&gt;- Long task in general.&lt;br /&gt;
&lt;br /&gt;
- For tasks in parallel use Multiple threads (traditional mechanisms)&lt;/td&gt;&lt;td&gt;- Long task &lt;b&gt;usually&lt;/b&gt; with no communication to main thread.&lt;br /&gt;
&lt;b&gt;(Update)&lt;/b&gt;- If communication is required, can use main thread handler or broadcast intents&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[3]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
- When callbacks are needed (Intent triggered tasks).&amp;nbsp;&lt;/td&gt;&lt;td&gt;- Long task having to communicate with main thread.&lt;br /&gt;
&lt;br /&gt;
- For tasks in parallel use multiple instances OR Executor &lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[1]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Trigger&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Call to method&lt;br /&gt;
onStartService()&lt;/td&gt;&lt;td&gt;Thread start() method&lt;/td&gt;&lt;td&gt;Intent&lt;/td&gt;&lt;td&gt;Call to method execute()&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Triggered From (thread)&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Any thread&lt;/td&gt;&lt;td&gt;Any Thread&lt;/td&gt;&lt;td&gt;Main Thread (Intent is received on main thread and then worker thread is spawed)&lt;/td&gt;&lt;td&gt;Main Thread&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Runs On (thread)&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Main Thread&lt;/td&gt;&lt;td&gt;Its own thread&lt;/td&gt;&lt;td&gt;Separate worker thread&lt;/td&gt;&lt;td&gt;Worker thread. However, Main thread methods may be invoked in between to publish progress.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Limitations /&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Drawbacks&lt;/b&gt;&lt;/td&gt;&lt;td&gt;May block main thread&lt;/td&gt;&lt;td&gt;- Manual thread management&lt;br /&gt;
&lt;br /&gt;
- Code may become difficult to read&lt;/td&gt;&lt;td&gt;- Cannot run tasks in parallel.&lt;br /&gt;
&lt;br /&gt;
- Multiple intents are queued on the same worker thread.&lt;/td&gt;&lt;td&gt;- one instance can only be executed once (hence cannot run in a loop) &lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[2]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
- Must be created and executed from the Main thread&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[1]&lt;/span&gt; API Level 11 (Android 3.0) introduces the executeOnExecutor() method, that runs multiple tasks on a thread pool managed by AsyncTask. Below API Level 11, we need to create multiple instances of AsyncTask and call execute() on them in order to start parallel execution of multiple tasks.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[2]&lt;/span&gt; Once you create an object of an AsyncTask and call execute, you cannot call execute on that object again. Hence, trying to run an AsyncTask inside a loop will require you to each time create a new object in the loop before calling the execute on it.&lt;br /&gt;
To be very precise, you cannot do something like :&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TestAsyncTask myATask = new TestAsyncTask();&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int i = 0; i &amp;lt; count; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myATask.execute("one", "two", "three", "four");&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: red; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
But you can do :&lt;/div&gt;&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int i = 0; i &amp;lt; count; i++) {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TestAsyncTask myATask = new TestAsyncTask();&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myATask.execute("one", "two", "three", "four");&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #38761d; font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;[3]&lt;/span&gt;&amp;nbsp;Thanks to comment posted by &lt;a href="http://commonsware.com/"&gt;Mark Murphy&lt;/a&gt; (&lt;a href="http://twitter.com/commonsguy"&gt;@commonsguy&lt;/a&gt;) : "&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; line-height: 18px;"&gt;&lt;i&gt;&lt;span class="Apple-style-span" style="font-family: Times, 'Times New Roman', serif;"&gt;there's nothing stopping an IntentService from communicating back to activities. A broadcast Intent is good for that, particularly with setPackage() to keep it constrained to your app (available on Android 2.1, IIRC). An ordered broadcast can be particularly useful, as you can rig it up such that if none of your activities are on-screen, that some manifest-registered BroadcastReceiver picks up the broadcast and raises a Notification.&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;"&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
With a pretty understanding of the AsyncTask and the IntentService classes provided by Android, it would be a good idea to leverage these for most of the tasks as against trying to manage threads manually or implement your class as a Service unless there is really a need to do so.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tricky Things:&lt;/b&gt;&lt;br /&gt;
There are some tricky scenarios that need some special handling. After all, we are dealing with a mobile environment and things are pretty unpredictable. For instance, the user opens your activity in which you start an AsyncTask, but before completion of the task, the user decides to exit the application (say by pressing the back button). Or your activity may be terminated (read kicked off) due to say an incoming call, when you are running a long task in the background. In such cases, where your application is not shutdown, but any foreground tasks have been closed or changed, all the background tasks need to know of this and try to exit gracefully.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-3870318216526378624?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/XUTiF4smDdJPrKAdQy5Um-P3-ew/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XUTiF4smDdJPrKAdQy5Um-P3-ew/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/XUTiF4smDdJPrKAdQy5Um-P3-ew/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/XUTiF4smDdJPrKAdQy5Um-P3-ew/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/6lPCD44LvZ8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/3870318216526378624/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-4.html#comment-form" title="18 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3870318216526378624?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3870318216526378624?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/6lPCD44LvZ8/android-thread-constructspart-4.html" title="Android Thread Constructs(Part 4): Comparisons" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>18</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/03/android-thread-constructspart-4.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D04ARnwyfyp7ImA9WhZTFEo.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-5990471083120983335</id><published>2011-03-18T12:19:00.000-07:00</published><updated>2011-03-18T12:19:07.297-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-18T12:19:07.297-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="doInBackground" /><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="AsyncTask" /><title>Android thread constructs (Part 3) : AsyncTask</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;After examining &lt;a href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html"&gt;thread communication&lt;/a&gt;, &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-1-ui.html"&gt;UI thread&lt;/a&gt; and then &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-2-intent.html"&gt;IntentService&lt;/a&gt;, I would like to talk about another threading construct called AsyncTask.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Similar to IntentService, AsyncTask allows us to run long running tasks in the background. However, unlike IntentService the implementation is not straight forward. One of the reason people might think is that it involves generics ! There is no need to be afraid about those really. We just need to know 2 important things. One is the type of data that will be moving around and secondly these types cannot be primitive types like int, float, boolean etc... Before going further into the implementation, let me try to explain at a conceptual level.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;u&gt;Concept&lt;/u&gt;:&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;You have a long task to do. You extend the AsycTask class and somewhere in there, specify your task. Then, from the main thread, create an instance of your extended class and call the execute() method. This should somehow result in a background thread executing your task. Pretty simple !&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Now, there are 3 kinds of data that you will be dealing with:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;1) Params : The parameters you pass on to the background task&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;2) Progress : The data units which the background task will be passing to you (UI thread) reporting its progress.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;3) Result : The data that will be returned by the background task (to the UI thread) on completion.&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;Clearly there seems to be a communication going on between the UI thread and the worker thread. Hence, I like to visualize the AsyncTask as follows:&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: left;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-NJh_n1acLI8/TYONMjr0LVI/AAAAAAAADis/WrmOmly41_k/s1600/Screen+shot+2011-03-18+at+12.49.15+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="405" src="https://lh6.googleusercontent.com/-NJh_n1acLI8/TYONMjr0LVI/AAAAAAAADis/WrmOmly41_k/s640/Screen+shot+2011-03-18+at+12.49.15+PM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;All the methods mentioned in the diagram will be a part of the extended AsyncTask class but however will run on different threads as indicated.&lt;br /&gt;
&lt;br /&gt;
1) You have an instance of the AsyncTask and will call the execute() method. This method runs on the UI thread and serves as a trigger to the platform to spawn a worker thread. &lt;br /&gt;
&lt;br /&gt;
2) Before handling the control to the worker thread, the platform will execute the onPreExecute() method on the main thread. We can perform any necessary task setup.&lt;br /&gt;
&lt;br /&gt;
3) After this method finishes, the platform executes the doInBackground() method on the worker thread.&lt;br /&gt;
&lt;br /&gt;
4,5) Now, whenever the worker thread calls the publishProgress() method, the platform calls the onProgressUpdate() method on the main thread with the parameters passed to the publishProgress() method.&lt;br /&gt;
&lt;br /&gt;
6,7) Finally when the long running task is over i.e. the doInBackground() method returns, the return value is passed to the onPostExecute() method.&lt;br /&gt;
&lt;br /&gt;
And, for all this to happen our AsyncTask class needs to know the datatypes for the 3 kinds of data discussed above.&lt;br /&gt;
&lt;br /&gt;
It is important to note that just like IntentService, AsycTask also spawns a SINGLE worker thread and hence only one task can be run in background. Furthermore, once an instance of our AsyncTask is created, you can call the execute() method on it only ONCE. An exception will be thrown if you try to call execute() on the same instance of AsyncTask more than once. Hence, with AsyncTask if you want to run multiple tasks in background, create multiple instances and call execute on them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;Note&lt;/b&gt;: API level 11 (Honeycomb) adds the executeOnExecutor() method which enables to run multiple tasks on a pool of threads managed by AsyncTask class. I have not studied and tried this. I will update the post (or write a new one) once I try this out.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Implementation details&lt;/u&gt;:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Extend the AsyncTask class and pass to it the datatypes for Params, Progress and Result&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class TestAsyncTask extends AsyncTask&amp;lt;String, Integer, Integer&amp;gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So, here, we are telling that our worker thread will accept String parameters as input, the worker thread may publish the progress to the main thread as an Integer value and finally the return value of the doInBackground method will be an Integer. Note that the Integer class is used instead of primitive data type int.&lt;br /&gt;
&lt;br /&gt;
Now, It may happen that, you have a worker thread that doesn't need any input, doesn't wish to convey any progress or any result. In that case, the AsyncTask definition will look like:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class TestAsyncTask extends AsyncTask&amp;lt;Void, Void, Void&amp;gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Okay. Sticking with the first example, lets add in the doInBackground, onProgressUpdate and onPostExecute methods.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class TestAsyncTask extends AsyncTask&amp;lt;String, Integer, Integer&amp;gt; {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;protected Integer doInBackground(String... strings) {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Long running task - say processing of each passed string&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for (int i = 0; i &amp;lt; strings.length; i++){&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do processing of strings[i]&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;publishProgress(i); // publish that ith string is processed&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 0;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;protected void onProgressUpdate(Integer... item){&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Log.d("TestP", item[0] + " item has been processed");&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;protected void onPostExecute(Integer result){&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Log.d("TestP", "AsyncTask returned : " + result);&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
From the main thread (say from your Activity or service), create an instance of the AsyncTask.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TestAsyncTask myATask = new TestAsyncTask();&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myATask.execute("one", "two", "three", "four");&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;As mentioned before, if you want to run multiple AsyncTasks in parallel, just create another instance and call execute on it.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TestAsyncTask myATask2 = new TestAsyncTask();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myATask2.execute("five", "six", "seven", "eight");&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;There are 4 threading rules we need to follow for AsyncTask to work properly. These are mentioned in the AsyncTask &lt;a href="http://developer.android.com/reference/android/os/AsyncTask.html"&gt;documentation&lt;/a&gt;, &amp;nbsp;but I'll mention those again so that everything is available at one place.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;1. The task instance needs to be created on the main thread.&lt;/div&gt;&lt;div&gt;2. The execute() method needs to be called on the main thread.&lt;/div&gt;&lt;div&gt;3. Do not&amp;nbsp;&amp;nbsp;explicitly&amp;nbsp;call any of the preExecute(), postExecute(), doInBackground() and onProgressUpdate() methods.&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;4. The task can be executed only once on one instance.&lt;br /&gt;
&lt;br /&gt;
Thats all you need to know to execute AsyncTask.&lt;br /&gt;
I'm pretty much excited about my next post. I'm planning to do a comparison of various background mechanisms that we have seen till now as well as try to come up with some guidelines. I'm still working on it, hope to post them soon. Stay tuned !&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-5990471083120983335?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0s-AhPl4C_MCzixUP4yI6pZvtmE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0s-AhPl4C_MCzixUP4yI6pZvtmE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0s-AhPl4C_MCzixUP4yI6pZvtmE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0s-AhPl4C_MCzixUP4yI6pZvtmE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/nUR5F6XZBmE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/5990471083120983335/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/03/android-thread-constructs-part-3.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/5990471083120983335?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/5990471083120983335?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/nUR5F6XZBmE/android-thread-constructs-part-3.html" title="Android thread constructs (Part 3) : AsyncTask" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh6.googleusercontent.com/-NJh_n1acLI8/TYONMjr0LVI/AAAAAAAADis/WrmOmly41_k/s72-c/Screen+shot+2011-03-18+at+12.49.15+PM.png" height="72" width="72" /><thr:total>5</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/03/android-thread-constructs-part-3.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUQCRnw9eyp7ImA9WhZTFEs.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-5379104006683349717</id><published>2011-03-17T20:35:00.000-07:00</published><updated>2011-03-18T09:56:07.263-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-18T09:56:07.263-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IntentService" /><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="background task" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Android Thread Constructs(Part 2): Intent Service</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Continuing from &lt;a href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-1-ui.html"&gt;Part 1&lt;/a&gt; about the UI thread, today, I would like to discuss the IntentService class.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Concept&lt;/u&gt;:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
In simple terms, IntentService provides a mechanism to run a long task in the background. We need not worry of any thread creation and management. It is all done behind the scene. We just extend our class from the IntentService class, and implement our long task in the overridden onHandleIntent() method.&lt;br /&gt;
&lt;br /&gt;
On the specified trigger (which is an Intent), the platform will spawn a worker thread for our extended class and then call the onHandleIntent method on this thread. I like to visualize this as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-GPeJEXC7Zag/TYJ0SnBpQkI/AAAAAAAADik/0lmkcBJqSVo/s1600/Screen+shot+2011-03-17+at+4.38.05+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="329" src="https://lh6.googleusercontent.com/-GPeJEXC7Zag/TYJ0SnBpQkI/AAAAAAAADik/0lmkcBJqSVo/s640/Screen+shot+2011-03-17+at+4.38.05+PM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;So, all the long running code can be executed in the onHandleIntent() method. We can be sure that this will not block the main (UI) thread.&lt;br /&gt;
&lt;br /&gt;
It is worth noting here that if there are &lt;b&gt;multiple intents&lt;/b&gt; that are received, they all will &lt;b&gt;NOT execute in&amp;nbsp;parallel.&lt;/b&gt; The IntentService class spawn a &lt;b&gt;SINGLE worker thread.&lt;/b&gt; Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.&lt;br /&gt;
&lt;br /&gt;
So, the obvious question is :&amp;nbsp;What if I want to execute multiple tasks in parallel ?&lt;br /&gt;
&lt;br /&gt;
I will defer to answer this till the end of this article series. We will first go through AsyncTask in the next article and then the concluding post I will try to consider various use cases, limitations and comparisons.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Implementation details&lt;/u&gt;:&lt;/b&gt;&lt;br /&gt;
Now for some implementation details. Extend your class (say MyIntentService) as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class MyIntentService extends IntentService {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public MyIntentService() {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;super ("com.foo.MyIntentService");&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;protected void onHandleIntent(Intent intent) {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// call to any long running task !&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Thats it. You are all set ! Now, you can trigger this by calling the startService(Intent) method. We need not worry about stopping the service. &lt;b&gt;Once the long running task is done and if there are no intents lined up in the message queue, the platform will automatically stop the IntentService.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I have stated again and again, IntentService is very useful when you need to perform a long task in the background. The interesting part here is that the trigger for starting the task is an Intent ! Now that opens a lot of&amp;nbsp;opportunities.&amp;nbsp;Don't get it ? &amp;nbsp;Here is hint :&amp;nbsp;Your application need not be running at the time you want to start a background task ! All you need to do is have a PendingIntent for your IntentService. Now you can register this PendingIntent with many of the available callbacks in the Android APIs. So, now, even if your application is not running, and the PendingIntent is fired ! Wolaa - your background task is started &amp;nbsp;:)&lt;br /&gt;
&lt;br /&gt;
Coming up next is AsyncTask.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-5379104006683349717?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/EWJ75XMUzRgGx3kIyL4ND4nUFS0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EWJ75XMUzRgGx3kIyL4ND4nUFS0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/EWJ75XMUzRgGx3kIyL4ND4nUFS0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/EWJ75XMUzRgGx3kIyL4ND4nUFS0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/roUsjlCEaWY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/5379104006683349717/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-2-intent.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/5379104006683349717?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/5379104006683349717?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/roUsjlCEaWY/android-thread-constructspart-2-intent.html" title="Android Thread Constructs(Part 2): Intent Service" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh6.googleusercontent.com/-GPeJEXC7Zag/TYJ0SnBpQkI/AAAAAAAADik/0lmkcBJqSVo/s72-c/Screen+shot+2011-03-17+at+4.38.05+PM.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/03/android-thread-constructspart-2-intent.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CU8ASH0yeyp7ImA9Wx9aGEU.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-3370174312687545124</id><published>2011-03-11T14:50:00.000-08:00</published><updated>2011-03-11T14:50:49.393-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-11T14:50:49.393-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Main Thread" /><category scheme="http://www.blogger.com/atom/ns#" term="UI thread" /><category scheme="http://www.blogger.com/atom/ns#" term="IntentService" /><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="AsyncTask" /><title>Android Thread Constructs(Part 1): The UI Thread</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Earlier, I &lt;a href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html"&gt;talked&lt;/a&gt; on passing data between threads. I would like to continue the same "thread" of discussion and in the next few posts of this multipart article, explore and try to explain about various ways of performing tasks.&lt;br /&gt;
&lt;br /&gt;
A&amp;nbsp;pictorial and&amp;nbsp;diagrammatic&amp;nbsp;representation makes me understand concepts well. Every time I learn something new, I try to make a diagram in my mind. This helps me understand better. So, I'll be providing my own diagrams along the way.&lt;br /&gt;
&lt;br /&gt;
Note : The diagrams I use are to help myself understand the concept and may not be an exact representation of the concept. You may still need to read the related documentation.&lt;br /&gt;
&lt;br /&gt;
Enough said, lets get into the Thread !&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The UI Thread:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So, in an Android application, each application is sandboxed and runs in its own process. Unlike traditional languages, the Android application may not have a single entry point. So, the application can be entered through from any of the application components (Activities, Services, Broadcast receivers) described in the &lt;a href="http://developer.android.com/guide/topics/fundamentals.html"&gt;Application Fundamentals&lt;/a&gt; on the developer blog.&lt;br /&gt;
&lt;br /&gt;
All these application components run on a single Main thread called as the UI thread. I like to imagine this concept as in figure below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh5.googleusercontent.com/-ybTwPnIie9w/TXqSor8wv1I/AAAAAAAADh0/-5XZlbj4_Tw/s1600/Screen+shot+2011-03-11+at+4.04.12+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="https://lh5.googleusercontent.com/-ybTwPnIie9w/TXqSor8wv1I/AAAAAAAADh0/-5XZlbj4_Tw/s400/Screen+shot+2011-03-11+at+4.04.12+PM.png" width="336" /&gt;&lt;/a&gt;&lt;/div&gt;So, as you see all the components will run on the MainThread or the UI thread. &lt;b&gt;All the lifecycle methods (of Activity, Service, Receivers starting with on*) will run on the UI thread.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
One of the &lt;b&gt;main task of the UI thread is to manipulate the user interface.&lt;/b&gt; Hence, if you have long tasks to perform, you should not be doing those in the main thread. (I'm sure, you must have read this several times). The reason is that if you perform any long or blocking task - the UI thread will be blocked - hence blocking or delaying the UI updates and will lead the user to think that the system is running slow. The Android platform doesn't want this blame on itself, so when it detects that some long task is running on the UI thread for some application, it will declare that the application is "foobar-ed" and throw out the nasty ANR (Application Not Responding) dialog - pissing off the user and provoking him/her to uninstall, and underrate your application ! Deadly and Evil &amp;nbsp;:O&lt;br /&gt;
&lt;br /&gt;
So, &lt;b&gt;in order to do longer tasks, from any of the application components, you should create threads. &lt;/b&gt;However, its worth noting that you should not manipulate the UI from any worker thread. i.e for example if you run a long task on a thread on a button click as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #333333; font-family: arial, sans-serif; font-size: 14px;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class="prettyprint" style="background-color: #fafafa; border-bottom-color: rgb(204, 204, 204); border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(204, 204, 204); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(204, 204, 204); border-top-style: solid; border-top-width: 1px; color: #007000; font-family: monospace; line-height: inherit; margin-bottom: 1em; margin-left: 1em; margin-right: 0px; margin-top: 0px; overflow-x: auto; overflow-y: auto; padding-bottom: 10px; padding-left: 10px; padding-right: 10px; padding-top: 10px;"&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;void&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; onClick&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;(&lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;View&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; v&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;)&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;new&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Thread&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;(&lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;new&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Runnable&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;()&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;public&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="kwd" style="color: #000088;"&gt;void&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; run&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;()&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;{&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="typ" style="color: #660066;"&gt;Bitmap&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; b &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;=&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt; loadImageFromNetwork&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;();&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; mImageView&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;.&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;setImageBitmap&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;(&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;b&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;);&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&amp;nbsp; &lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}).&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;start&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;();&lt;/span&gt;&lt;span class="pln" style="color: black;"&gt;
&lt;/span&gt;&lt;span class="pun" style="color: #666600;"&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;span class="Apple-style-span" style="font-size: x-small;"&gt;Code source :&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: xx-small;"&gt;&amp;nbsp;&lt;a href="http://developer.android.com/resources/articles/painless-threading.html"&gt;http://developer.android.com/resources/articles/painless-threading.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Here, the worker thread is trying to update the UI. As the &lt;a href="http://developer.android.com/resources/articles/painless-threading.html"&gt;documentation&lt;/a&gt; states, this may lead to hard to find and funny (not for you) problems.&amp;nbsp;So, &lt;b&gt;updating the UI is the job of the main thread.&lt;/b&gt; The following figure helps me remember that :)&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh4.googleusercontent.com/-4Bmyt6bb29c/TXqSq4DKmwI/AAAAAAAADh4/9utLBq7rFuE/s1600/Screen+shot+2011-03-11+at+4.04.28+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="295" src="https://lh4.googleusercontent.com/-4Bmyt6bb29c/TXqSq4DKmwI/AAAAAAAADh4/9utLBq7rFuE/s400/Screen+shot+2011-03-11+at+4.04.28+PM.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Now, it is evident and advisable that we do long and/or blocking tasks on worker threads and if any results are produced, convey them to the main thread. In my previous &lt;a href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html"&gt;article&lt;/a&gt;, I talked about passing data around threads. This involves implementing Handlers, making appropriate Looper calls, obtaining the Message Object and passing it around, getting data from it blah blah blah... (Go &lt;a href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html"&gt;read&lt;/a&gt; the article if you havent')&lt;br /&gt;
&lt;br /&gt;
Android provides certain constructs that offload from us the tasks for creation and administration of threads and let us focus on what we need to do. IntentService, AsyncTask, HandlerThread are among those.&lt;br /&gt;
&lt;br /&gt;
I'm going to discuss IntentService and AsyncTask (with my diagrammatic representations) in the next articles and then try to come up with rough guidelines regarding when to use each of the constructs.&lt;br /&gt;
&lt;br /&gt;
Stay tuned.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-3370174312687545124?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Vcjb93m_Glyt9tM-6bDXPS9wacA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Vcjb93m_Glyt9tM-6bDXPS9wacA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Vcjb93m_Glyt9tM-6bDXPS9wacA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Vcjb93m_Glyt9tM-6bDXPS9wacA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/q4eU0iiRgbY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/3370174312687545124/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/03/android-thread-constructspart-1-ui.html#comment-form" title="15 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3370174312687545124?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3370174312687545124?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/q4eU0iiRgbY/android-thread-constructspart-1-ui.html" title="Android Thread Constructs(Part 1): The UI Thread" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh5.googleusercontent.com/-ybTwPnIie9w/TXqSor8wv1I/AAAAAAAADh0/-5XZlbj4_Tw/s72-c/Screen+shot+2011-03-11+at+4.04.12+PM.png" height="72" width="72" /><thr:total>15</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/03/android-thread-constructspart-1-ui.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEARHgzfCp7ImA9Wx9bFko.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-4563584573769438356</id><published>2011-02-25T14:57:00.000-08:00</published><updated>2011-02-25T14:57:25.684-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-25T14:57:25.684-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="GRI40" /><category scheme="http://www.blogger.com/atom/ns#" term="2.3.3" /><category scheme="http://www.blogger.com/atom/ns#" term="status 7" /><category scheme="http://www.blogger.com/atom/ns#" term="gingerbread" /><category scheme="http://www.blogger.com/atom/ns#" term="installation aborted" /><category scheme="http://www.blogger.com/atom/ns#" term="assert failed" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Getting gingerbread on Nexus One</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;If you are an impatient person like me (when it comes to gadgets !), with a nexus one but no gingerbread yet, you might definitely be aware that there are official versions of Gingerbread 2.3.3 floating out there.&lt;br /&gt;
&lt;br /&gt;
I faced some problems getting gingerbread to my N1.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noobie_skip&amp;gt;&lt;br /&gt;
I had CM7 on my nexus one which is gingerbread but I wanted to get to a stock version (why ? my choice :D and for some reason gapps wasn't able to install the GMail app on CM7 !) Noobies, you are supposed to ignore this block&lt;br /&gt;
&amp;lt;/noobie_skip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, I was able to get back to stock version 2.2 using instructions &lt;a href="http://forum.androidcentral.com/423356-post1.html"&gt;here&lt;/a&gt;. From then on my impatience triggered ignorance and things started to go foo bar !&lt;br /&gt;
&lt;br /&gt;
I started getting a very strange error. Something like :&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #464646; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 13px;"&gt;assert failed: file_getprop(“/system/build.prop”, “ro.build.fingerprint”) == “google/passion/passion/mahimahi:2.2.2/FRG83G/91102:user/release-keys” ll file_getprop(“/system/build.prop”, “ro.build.fingerprint”) == “google/passion/passion/mahimahi:2.3.3/GRI40/102588:user/release-keys”&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #464646; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 13px;"&gt;E:Error in /sdcard/update.zip&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #464646; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 13px;"&gt;(status 7)&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #464646; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 13px;"&gt;Installation aborted&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="color: #464646; font-family: Arial, 'Trebuchet MS', sans-serif; font-size: 13px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="color: black; font-family: Times; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Eventually, I figured out that I was trying to directly jump from FRG33 to GRI40 (This is Gingerbread 2.3.3) ! All the zip files floating out there are incremental - they only take you one level up !&lt;/div&gt;&lt;div style="color: black; font-family: Times; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="color: black; font-family: Times; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;So, you may want to check the file name. For e.g. :&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;2854b06b22b9.signed-passion-FRG83G-from-FRG83D.2854b06b.zip&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;This file will take you from FRG83D to FRG83G. You will need to go on flashing each one. So find all the zip files that will take you from your version up to GRI40&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;For me it was from FRG83 -&amp;gt; FRG83D, then FRG83D -&amp;gt; FRG83G and finally FRG83G -&amp;gt; GRI40&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Wooohooooo. Gingerbread it is !&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Hope this helps someone !&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Note: Unfortunately I cannot provide you with all the zip file paths. Since the links may be broken or get broken over time and I do not wish to keep on updating those. Use our friend Google to get to the files ! :)&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-4563584573769438356?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zFoLXINQ88OfgahKcv1Wcp3QBi4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zFoLXINQ88OfgahKcv1Wcp3QBi4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zFoLXINQ88OfgahKcv1Wcp3QBi4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zFoLXINQ88OfgahKcv1Wcp3QBi4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/5N4CdOWzrdU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/4563584573769438356/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/02/getting-gingerbread-on-nexus-one.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/4563584573769438356?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/4563584573769438356?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/5N4CdOWzrdU/getting-gingerbread-on-nexus-one.html" title="Getting gingerbread on Nexus One" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>0</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/02/getting-gingerbread-on-nexus-one.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0QERX4yeSp7ImA9Wx9bEEw.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-7419839365794294120</id><published>2011-02-17T22:41:00.000-08:00</published><updated>2011-02-17T22:41:44.091-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-17T22:41:44.091-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="looper" /><category scheme="http://www.blogger.com/atom/ns#" term="threads" /><category scheme="http://www.blogger.com/atom/ns#" term="handlerthread" /><category scheme="http://www.blogger.com/atom/ns#" term="handler" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="message passing" /><title>Android : Passing data between main thread and worker threads.</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;There may be situations where you want to spawn a thread from your Activity or Service to handle long running (and may be blocking) tasks. In such cases, its sometimes necessary to pass data back and forth between the main thread and the worker thread(s). E.g. if the worker thread finishes a task and returns the result to the main activity to display the results OR you want to keep a worker thread around and ask it to switch between tasks depending on some message you pass to it.&lt;br /&gt;
&lt;br /&gt;
In the past, I faced some problems understanding these concepts associated with different classes in android.os like the Handler, Looper, HandlerThread etc...&lt;br /&gt;
&lt;br /&gt;
I'll try to explain these concepts in a simple language. Probably most of these&amp;nbsp;explanations&amp;nbsp;are from the developer documentation, but I thought consolidating these at one place may help to get a good picture.&lt;br /&gt;
&lt;br /&gt;
Ok. So, when an application runs, it runs in a Main thread called as the UI thread. Any other thread can be created using the standard java.lang.Thread class. As I said in a typical situation you will spawn a thread, may be pass some data to it OR the thread may pass back some data to the Main thread from time to time as well as when its done executing.&lt;br /&gt;
&lt;br /&gt;
Let us consider the task where we need to send data to a worker thread. So first, we create a worker thread.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;STEP 1: Create a worker thread&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class MyThread extends Thread {&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;@Override&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public void run(){&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In our main thread...&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;MyThread mThread = new MyThread();&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;mThread.start();&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;When you have to pass any messages to a thread or get messages from a thread, the &lt;i&gt;receiving&lt;/i&gt; thread needs a MessageQueue.&lt;/b&gt;&amp;nbsp;By default, a thread created by using the java.lang.Thread class will not have a MessageQueue associated with it. Its just a plain old thread as in the Fig. 1 (Yes, I know. What an innovative diagram !! :D ).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-cTfO36YWcDI/TV4BFYLMDLI/AAAAAAAADgU/bWz_LnYVYSU/s1600/Th_JAT.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="140" src="http://4.bp.blogspot.com/-cTfO36YWcDI/TV4BFYLMDLI/AAAAAAAADgU/bWz_LnYVYSU/s200/Th_JAT.png" width="200" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Now, we need to attach a MessageQueue to our thread.&amp;nbsp;The &lt;a href="http://developer.android.com/reference/android/os/Looper.html"&gt;Looper&lt;/a&gt; class provides the method prepare() to create a message queue for a thread. We need to call this method from the &lt;i&gt;receiving&lt;/i&gt;&amp;nbsp;thread's run method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;STEP 2: Call the Looper methods&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class MyThread extends Thread {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;@Override&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public void run(){&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Looper.prepare();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Looper.loop();&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;As you see, there is one more Looper method called in the code. This loop() method will start running the message loop for the current thread. In simple terms, it will start looking at the MessageQueue and processing the messages. This is how I interpret the Looper as in Fig. 2.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;a href="http://4.bp.blogspot.com/-ax1gVMVsIp8/TV4BGNY6dUI/AAAAAAAADgc/93rXYDb9uGs/s1600/Th_TWL.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="156" src="http://4.bp.blogspot.com/-ax1gVMVsIp8/TV4BGNY6dUI/AAAAAAAADgc/93rXYDb9uGs/s320/Th_TWL.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;But, who sends the messages to the MessageQueue and how are these processed ? There is a class called the &lt;a href="http://developer.android.com/reference/android/os/Handler.html"&gt;Handler&lt;/a&gt;. The Hander allows us to send and process &lt;a href="http://developer.android.com/reference/android/os/Message.html"&gt;Message&lt;/a&gt;s (as well as Runnable Objects) associated with the thread's MessageQueue. So, we need to create a Handler. &lt;b&gt;It is important to note that the Handler is associated with the thread that creates it ! &lt;/b&gt;The Handler provides methods to handle (receive) Messages as well as send and schedule messages. For details, please refer to &lt;a href="http://developer.android.com/reference/android/os/Handler.html"&gt;documentation&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;STEP 3: Create a Handler to receive the Messages&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class MyThread extends Thread {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public Handler mHandler;&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;@Override&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public void run(){&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Looper.prepare();&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mHandler = new Handler() {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public void handleMessage(Message msg) {&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Act on the message&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Looper.loop();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;If you notice, this code is the same that is listed on the Looper&amp;nbsp;documentation&amp;nbsp;page &lt;a href="http://developer.android.com/reference/android/os/Looper.html"&gt;here&lt;/a&gt;. &amp;nbsp;Few things to mention here are. The Handler is created in this thread, hence it is associated with the default Looper (read MessageQueue) in the current thread. There are constructors for the Handler that allow us to specify the Looper&amp;nbsp;(again, read MessageQueue). This allows us to write a cleaner code by writing the Handler class separately and passing on a Looper&amp;nbsp;(again, again, read MessageQueue)&amp;nbsp;when the Handler is created. I'll get to this in a while. But as I have insisted, it is worth noting that whenever the developer documentation refers to a Looper, you can assume they are talking about a queue. I'm really not sure why they have surfaced the Looper class. It creates more confusion (at least for me). Also, when dealing with passing the messages, with this mechanism, we really need not care of the MessageQueue call. That is the reason I haven't linked it to the documentation. Anyways... things are what they are ! For me, I like to interpret this whole mechanism as depicted in Fig. 3.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;a href="http://1.bp.blogspot.com/--UJ07s6ONTI/TV4BF_zYuGI/AAAAAAAADgY/N5MXF4PY2zA/s1600/Th_PAT.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="162" src="http://1.bp.blogspot.com/--UJ07s6ONTI/TV4BF_zYuGI/AAAAAAAADgY/N5MXF4PY2zA/s320/Th_PAT.png" style="cursor: move;" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Let me know if you like PAT or your way of viewing it !&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So, now any other thread having the reference to mHandler will be able to call the send or post methods of the Handler class to send a Message (or a runnable object) to our thread. The code for sending message will look like:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Message msg = Message.obtain();&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;msg.obj = &amp;nbsp;// Some Arbitrary object&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;mHandler.sendMessage(msg);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Pretty simple yeah ! Btw, there are various methods to set/get data for the Message object which can be found in the developer documentation for the Message class.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;Summary of Steps :&lt;/b&gt;&lt;/div&gt;&lt;div&gt;1. Create a Handler in the receiving thread [If it is the main thread, create one in the main thread]. By default the handler will be associated with the default queue (Looper).&lt;/div&gt;&lt;div&gt;2. So, if the receiving thread is created by using java.lang.Thread, then we need to call the Looper.prepare() and Looper.loop() in order to set up the message queue for the thread.&lt;/div&gt;&lt;div&gt;3. &amp;nbsp;In the sending thread, prepare a message object (or a Runnable object)&lt;/div&gt;&lt;div&gt;4. Get a reference to the Handler in the sending thread and call the send/post methods on it to send a message.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;HandlerThread&lt;/b&gt;:&lt;/div&gt;&lt;div&gt;Since by default java.lang.Thread doesn't contain a message queue (Looper), Android provides a class called as the HandlerThread which already contains a message queue. The only difference in using the HandlerThread class over the method described above is that you need not call the Looper.* methods.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;On creation of a HandlerThread, Android will create a thread containing the looper. So, in the main thread the code will look like:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;HandlerThread myThread = new HandlerThread("Worker&amp;nbsp;Thread"); &amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;myThread.start();&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: 12px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;We separately create a Handler as follows:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;class MyHandler extends Handler {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;public MyHandler(Looper myLooper) {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;super(myLooper);&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;public void handleMessage(Message msg) {&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;
}&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now in the main thread, we get the looper for the HandlerThread and pass it when we create the Handler as follows:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Looper mLooper = myThread.getLooper();&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;MyHandler mHandler = new MyHandler(mServiceLooper);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Whenever we want to send a message from the main thread, we do it in a similar fashion.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;Message msg = mHandler.obtainMessage();&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-family: Times;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;msg.obj = &amp;nbsp;// Some Arbitrary object&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"&gt;mHandler.sendMessage(msg);&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;&lt;div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small;"&gt;I like to visualize this as shown below in Fig. 4 where we write the Handler separately and then pass a looper to it on its creation.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: arial, sans-serif; font-size: 12px; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-l5rPe75ERhg/TV4JrKyAtEI/AAAAAAAADgg/uCvQAVtYqLQ/s1600/Th_HT.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="147" src="http://2.bp.blogspot.com/-l5rPe75ERhg/TV4JrKyAtEI/AAAAAAAADgg/uCvQAVtYqLQ/s400/Th_HT.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: arial, sans-serif; font-size: 12px;"&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-7419839365794294120?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uazFhyU8amS7I49zgOg_ZvxZ9nc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uazFhyU8amS7I49zgOg_ZvxZ9nc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uazFhyU8amS7I49zgOg_ZvxZ9nc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uazFhyU8amS7I49zgOg_ZvxZ9nc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/SzzBgxND4GQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/7419839365794294120/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html#comment-form" title="8 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/7419839365794294120?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/7419839365794294120?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/SzzBgxND4GQ/android-passing-data-between-main.html" title="Android : Passing data between main thread and worker threads." /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-cTfO36YWcDI/TV4BFYLMDLI/AAAAAAAADgU/bWz_LnYVYSU/s72-c/Th_JAT.png" height="72" width="72" /><thr:total>8</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/02/android-passing-data-between-main.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUEEQ38-fSp7ImA9Wx9UFE4.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-3857038335560603249</id><published>2011-02-11T07:20:00.000-08:00</published><updated>2011-02-11T07:20:02.155-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-11T07:20:02.155-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="nokia" /><category scheme="http://www.blogger.com/atom/ns#" term="wp7" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Nokia chooses WP7 over Android</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Going through the news reader this morning, I learnt that Nokia, one of the greatest manufacturers of mobile devices has chosen WP7 over Android. Not that I hate WP7 (as of yet, since I haven't tried it), but I would have loved to have my favorite Android on Nokia devices.&lt;br /&gt;
Being from India, where Nokia phones are seen as prime devices (at least till recently), and having used few of Nokia phones before, I was eagerly waiting to hear Nokia adopt Android.&lt;br /&gt;
Now, it will be an interesting market to see. I'm not much concerned how this affects WP7 (sorry Microsoft, not a big fan), though for the time being it will definitely be a breather for them. I'm worried about the future of Nokia. But still I hope that somewhere in future, Nokia will shake hands with the green robot !&lt;br /&gt;
&lt;br /&gt;
BTW, did I hear somewhere that Nokia CEO Stephen Elop is a former Microsoft employee ! Ahem ahem ...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-3857038335560603249?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/PmtAZ7PbxolQOhRwqVYfXCXas8U/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PmtAZ7PbxolQOhRwqVYfXCXas8U/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/PmtAZ7PbxolQOhRwqVYfXCXas8U/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/PmtAZ7PbxolQOhRwqVYfXCXas8U/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/u3stjvPhGd4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/3857038335560603249/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/02/nokia-chooses-wp7-over-android.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3857038335560603249?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3857038335560603249?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/u3stjvPhGd4/nokia-chooses-wp7-over-android.html" title="Nokia chooses WP7 over Android" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>0</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/02/nokia-chooses-wp7-over-android.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ak4CSHs_fSp7ImA9Wx9aEUU.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-1509926526891593366</id><published>2011-02-10T14:00:00.000-08:00</published><updated>2011-03-03T13:49:29.545-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-03-03T13:49:29.545-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="development" /><category scheme="http://www.blogger.com/atom/ns#" term="emulator" /><category scheme="http://www.blogger.com/atom/ns#" term="geo fix" /><category scheme="http://www.blogger.com/atom/ns#" term="sms" /><category scheme="http://www.blogger.com/atom/ns#" term="commands" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Android development cheatsheet</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Here is a list of commands I find useful when developing applications. Do add to comments any commands that you use and find useful. I'll update accordingly. Also, I would be interested if anyone has any android UI related cheat sheets :)&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;u&gt;android&lt;/u&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;/div&gt;&lt;div class="MsoListParagraphCxSpFirst" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: -0.25in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;-&lt;span style="font: normal normal normal 7pt/normal 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;Create/delete/view Android Virtual Devices&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoListParagraphCxSpMiddle" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: -0.25in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;-&lt;span style="font: normal normal normal 7pt/normal 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;Create/update projects&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoListParagraphCxSpLast" style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-indent: -0.25in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;-&lt;span style="font: normal normal normal 7pt/normal 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;Update the SDK with new platforms, addons and docs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;android list target&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;android list avd&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;android --help&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;&lt;span class="Apple-style-span" style="line-height: normal;"&gt;&lt;/span&gt;android create avd –n &amp;lt;avd_name&amp;gt; -t &amp;lt;target_ID&amp;gt; -c &amp;lt;size&amp;gt;[K|M]&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;android create project --target &amp;lt;target_ID&amp;gt; --name &amp;lt;prjname&amp;gt; --path &amp;lt;where&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; --activity&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;&amp;lt;activityname&amp;gt; --package &amp;lt;package_namespace&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; line-height: 14px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;android update project [--name|-n] &amp;lt;prjname&amp;gt; [--target|-t] &amp;lt;target_ID&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [--path|-p] &amp;lt;thepath_to_prj&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;android create lib-project --target &amp;lt;target_ID&amp;gt; --name &amp;lt;prjname&amp;gt; --path &amp;lt;where&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; --&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px;"&gt;package &amp;lt;package_namespace&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small;"&gt;adb&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri; font-size: 11pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;adb [-d|-e] install &amp;lt;path_to_your_bin&amp;gt;.apk&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;adb push &amp;lt;local&amp;gt; &amp;lt;remote&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;- copy file/dir to device&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;adb pull &amp;lt;remote&amp;gt; [&amp;lt;local&amp;gt;]&amp;nbsp;&amp;nbsp;- copy file/dir from device&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;e.g : adb push foo.txt /sdcard/foo.txt&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;adb shell&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;adb devices&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;adb –s emulator-5554 shell&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;#sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;sqlite&amp;gt;.exit&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;adb logcat [&amp;lt;option&amp;gt; … [&amp;lt;filter-spec&amp;gt;] …&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;[V – Verbose, D – Debug, I – Info, W – Warning, E – Error, F – Fatal, S – Silent]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;adb logcat &amp;lt;tag1&amp;gt;:&amp;lt;priority1&amp;gt; …..&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: 'Courier New'; font-size: 9.5pt; margin-bottom: 0.0001pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;e.g. : adb logcat ActivityMgr:I MyApp:D *:S&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;&lt;o:p&gt;&lt;br /&gt;
&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;&lt;o:p&gt;&lt;u&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small; line-height: normal;"&gt;others&lt;/span&gt;&amp;nbsp;&lt;/u&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: Calibri; font-size: 11pt; line-height: 17px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="Apple-style-span" style="font-family: Times; font-size: small; line-height: normal;"&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;mksdcard [-l label] &amp;lt;size&amp;gt;[K|M] &amp;lt;file&amp;gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;emulator –avd &amp;lt;avd_name&amp;gt; –sdcard &amp;lt;file&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;telnet localhost &amp;lt;emulator-port&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;#From inside telnet:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;- sms send &amp;lt;sender phone number&amp;gt; &amp;lt;text message&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;span class="apple-style-span"&gt;&lt;span style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px;"&gt;- geo fix &amp;lt;longitude&amp;gt; &amp;lt;latitude&amp;gt; [&amp;lt;altitude&amp;gt;]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal" style="font-family: 'Courier New'; font-size: 9.5pt; line-height: 14px; margin-bottom: 10pt; margin-left: 0in; margin-right: 0in; margin-top: 0in;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-1509926526891593366?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/d8LVkRPUIpTOoNtprhUw87PAMJo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d8LVkRPUIpTOoNtprhUw87PAMJo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/d8LVkRPUIpTOoNtprhUw87PAMJo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/d8LVkRPUIpTOoNtprhUw87PAMJo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/M9nXy2QTwFs" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/1509926526891593366/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/02/android-development-cheatsheet.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/1509926526891593366?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/1509926526891593366?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/M9nXy2QTwFs/android-development-cheatsheet.html" title="Android development cheatsheet" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>2</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/02/android-development-cheatsheet.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0EEQnY-eCp7ImA9Wx9UEU4.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-9077195859705327335</id><published>2011-02-03T12:51:00.000-08:00</published><updated>2011-02-07T20:33:23.850-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-02-07T20:33:23.850-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="honeycomb" /><category scheme="http://www.blogger.com/atom/ns#" term="encryption" /><category scheme="http://www.blogger.com/atom/ns#" term="security" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Android 3.0 encryption : Initial Thoughts</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;br /&gt;
&lt;b&gt;A little background:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Few days back Google released a preview version for the Android 3.0 SDK code named HoneyComb. For quite some time now, the enterprise has been asking for device management features for the Android Platform. Blackberry has these features integrated into their solution. Recently Apple also embraced the initiative and supported enterprise features in their iOS 4.&lt;br /&gt;
&lt;br /&gt;
The obvious reason for these trends is due to the customer demands. Earlier, enterprises used to provide employees with smart phones (read blackberries) to access corporate resources. Blackberry was the only solution providing secure corporate access, encryption and security policies. However, with iPhone getting popular, the momentum shifted in last couple of years. Now, instead companies providing the smartphones, employees demand the type of phone they want and companies' IT departments have the daunting task to support these smartphones. These demands lead Apple to add device management support to iOS.&lt;br /&gt;
&lt;br /&gt;
Android seems to be a very different game. It is gaining a lot of popularity these days. The open nature of it has enabled the platform to be adopted by a huge number of manufactures resulting in a burst of Android powered devices. In the corporate world, employees are asking for supporting Android devices too.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Some initial thoughts (technical):&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In Froyo (Android 2.2), google introduced some device admin APIs. Using these, some basic device management functionalities could be achieved. (Device lock, set password, device wipe). However, one primary concern for corporates is Encryption !&lt;br /&gt;
&lt;br /&gt;
Just few days back, google released a preview version of honeycomb SDK.&amp;nbsp;This is my interpretation of the Encryption API found in HoneyComb preview SDK. I'll update the blog or write a new post when I learn more on this.&lt;br /&gt;
&lt;br /&gt;
As a device admin, an application first has to check weather Encryption is supported by the tablet (in hardware). I don't think there is software encryption algorithm in honeycomb. I'll be surprised to see a software encryption (it will defenitely slow down the tablet in my opinion - but who knows, there are always surprises in the world !).&lt;br /&gt;
&lt;br /&gt;
So, assuming there is hardware support, the admin app can test it (using the getStorageEncryptionStatus) and then call the start encryption method (setStorageEncryption). This will trigger the hardware encryption process. According the honeycomb preview api documentation, this will encrypt only the application storage area (i.e. all the internal memory - my guess) and may not the external memory (sd card).&lt;br /&gt;
&lt;br /&gt;
SDK documentation for the setStorageEncryption says:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;snip&amp;gt;&lt;br /&gt;
This policy controls encryption of the secure (application data) storage area. Data written to other areas (e.g. the directory returned by getExternalStorageDirectory() may or may not be encrypted.&lt;br /&gt;
&amp;lt;/snip&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I came across an &lt;a href="http://www.engadget.com/2011/02/02/android-3-0-honeycomb-can-encrypt-all-your-data-needs-a-full/"&gt;engaget article&lt;/a&gt;&amp;nbsp;that says that the motorola xoom has an option to encrypt the entire tablet. This is a bit incomplete and misleading. Does this mean that Motorola has extended honeycomb to encrypt the SD card as well ? Who knows, only time will tell. I'm curious to know what kind of encryption is supported - hardware/software. Will it (and how much) affect the performance ? and will this initiative please corporates and will they embrace Android devices ?&lt;br /&gt;
&lt;br /&gt;
Time will tell and if it tells me first, I'll update the blog :) Do leave any comments if you find any information or corrections.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-9077195859705327335?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/h4Afw2kk_BTZuxQ9MFenjU3udXE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h4Afw2kk_BTZuxQ9MFenjU3udXE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/h4Afw2kk_BTZuxQ9MFenjU3udXE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/h4Afw2kk_BTZuxQ9MFenjU3udXE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/rUPawStv6ks" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/9077195859705327335/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2011/02/android-30-encryption-initial-thoughts.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/9077195859705327335?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/9077195859705327335?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/rUPawStv6ks/android-30-encryption-initial-thoughts.html" title="Android 3.0 encryption : Initial Thoughts" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>0</thr:total><feedburner:origLink>http://techtej.blogspot.com/2011/02/android-30-encryption-initial-thoughts.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0INRn8_fyp7ImA9WhZQEkk.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-670954279907474717</id><published>2010-10-21T15:46:00.000-07:00</published><updated>2011-04-19T12:33:17.147-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2011-04-19T12:33:17.147-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="c2dm" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><category scheme="http://www.blogger.com/atom/ns#" term="push" /><title>Android C2DM Messaging (Server Push for Android Phones)</title><content type="html">&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;b&gt;UPDATE&lt;/b&gt;: Added diagrams to get concepts clear.&lt;br /&gt;
&lt;br /&gt;
From monday, I have been fighting to get the C2DM (Cloud to Device Messaging) working. And with somewhat frustration and a lot of help from some good people out there, I got it working ! :)&lt;br /&gt;
&lt;br /&gt;
In this article I describe my findings and try to explain the concepts in simple words and list out steps you need to do to get it working. For an example code I would suggest you take a look at Gabor's blog which is &amp;nbsp;&lt;a href="http://mylifewithandroid.blogspot.com/2010/10/push-service-from-google.html"&gt;this&lt;/a&gt;. Its really awesome.!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NOTE&lt;/b&gt;: Also,&amp;nbsp;I would suggest you to take a look at the&amp;nbsp;&lt;a href="http://code.google.com/android/c2dm/index.html#example"&gt;sample code&lt;/a&gt; provided by google.&amp;nbsp;If I get time, I will also post some sample code (don't wait for me to do that :D). Also, just take a look at the classes in the google.android.c2dm package provided in the sample codes. No need to dig into the details, but I may talk about them later in this post.&lt;br /&gt;
&lt;br /&gt;
So what is C2DM ? It is a server push mechanism provided by Google so that 3rd party applications can push messages to their applications on Android devices. Currently as of today, it is in beta, and if you are an enterprise, you will need to apply and have talks with Google before having your application out with a lot of users and lot of messages to push. However, for developers with a gmail account ID, the registration request should be pretty easily accepted and you will be "whitelisted".&lt;br /&gt;
&lt;br /&gt;
Before digging into details, let us see what are the top level concepts and which components are involved. Basically there are 3 entities involved:&lt;br /&gt;
0. The Google C2DM service.&lt;br /&gt;
1. Your server application. I'll call it as the "FOOServer". This will send the message to the C2DM service which will forward it to the requested device.&lt;br /&gt;
2. The application on the device that receives the message. I'll simply call it DeviceApp.&lt;br /&gt;
&lt;br /&gt;
So, no points to guess that C2DM acts as a middle man and does the message passing. How ? It uses the default google services on the Android phone. So the basic requirement for this whole thing to work is that &lt;i&gt;there should be at least one logged-in Google account from the device&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
Now, when you signup for the C2DM, you will be providing them with the following (only 2 relevant things are mentioned):&lt;br /&gt;
1. The Application Name. This is actually the package name that you will provide. &lt;i&gt;It is very important to remember this, because this is the package name you will have to use for your DeviceApp and worst part is that in the whitelisted mail that you get from Google, this is not mentioned.&lt;/i&gt;&amp;nbsp;I haven't found a way to look at our registered information. If anyone knows this, please comment and let me and other know. So, for the time being consider that the package name is "com.foo.test"&lt;br /&gt;
&lt;br /&gt;
2. The second important thing on the registration form is the Role Account Email ID. Make sure that this email is not used on any device. I have found that the messaging will not work for that device. So, for our example lets say it is FOO@gmail.com&lt;br /&gt;
&lt;br /&gt;
Just for fun, the following diagram depicts the above step.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-DW9rE2FAmmY/TaYcjHK7YMI/AAAAAAAADjM/chc1NqHb8W8/s1600/C2DM_01_signup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://4.bp.blogspot.com/-DW9rE2FAmmY/TaYcjHK7YMI/AAAAAAAADjM/chc1NqHb8W8/s320/C2DM_01_signup.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
So, till now, we have the email account ID which is FOO@gmail.com and the package name.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Who needs what&lt;/b&gt;&lt;br /&gt;
Ok, so how does each entity react to the C2DM and what IDs and credentials does it use ?&lt;br /&gt;
&lt;b&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;b&gt;DeviceApp&lt;/b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;The device app registers with the C2DM service. It tells the C2DM service that it would like to receive messages from FOOServer. In return it gets back a registration ID.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;So,&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;DeviceApp -----[FOO@gmail.com]------&amp;gt; C2DM&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;C2DM &amp;nbsp;--------[registrationID]--------&amp;gt; DeviceApp&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;The first action is done via a registration Intent. If you see the C2DMessaging class you will get this. Here, the DeviceApp sends the FOO@gmail.com address specifying that it would like to receive messages from this account.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Next, You will need to extend the C2DMBaseReceiver and override the onRegistered and onUnregistered methods. So, the onRegistered method will be called when the C2DM server accepts the registration. In this method you will receive a registrationID. This is a very long alpha numeric string that identifies the device.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Now, the DeviceApp needs to convey back this registration ID to the FOOServer. It is recommended that at this point you also send some unique device identifier to keep track on the FOOServer. The reason is that Google may change these registrationIDs and may not be unique. If Google changes any IDs it will push the new ID to the DeviceApp which has to handle it in similar fashion.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;So, if you choose say IMEI/MEID as the unique identifier, then,&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;DeviceApp -----[UniqueID, registrationID]------&amp;gt; FOOServer&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Thats it ! The device is now registered and ready to receive any messages. The following diagram shows this registration work flow:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-bottom: 0.5em; margin-left: auto; margin-right: auto; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-onCfikcfI-k/TaYckL-JxKI/AAAAAAAADjU/RINIRb4NURY/s1600/C2DM_03_Register.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-onCfikcfI-k/TaYckL-JxKI/AAAAAAAADjU/RINIRb4NURY/s1600/C2DM_03_Register.png" style="cursor: move;" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="font-size: 13px; padding-top: 4px; text-align: center;"&gt;Registration Work Flow&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;FOOServer:&lt;/b&gt;&lt;br /&gt;
The FOOServer will store (or update) the registrationID received into its local database. So, eventually the server will have registrationIDs from all the devices the DeviceApp is on. To send a message to a particular device, the FOOServer needs to POST to the C2DM Service the following &lt;s&gt;four&lt;/s&gt;&amp;nbsp;three things:&lt;br /&gt;
&lt;s&gt;1. The accountName which will be FOO@gmail.com&lt;/s&gt; (&lt;b&gt;Update : &lt;/b&gt;Thank you&lt;b&gt; @&lt;/b&gt;matest for pointing it out that this is not needed)&lt;br /&gt;
2. An authentication Token [explained below]&lt;br /&gt;
3. The registrationID of the device it wants to send the message.&lt;br /&gt;
4. The message itself ( I think the limit is 1024 charcters)&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
You can get the&amp;nbsp;authentication&amp;nbsp;token by providing the credentials for FOO@gmail.com. I used curl to get the token. In our case the command would be :&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas;"&gt;curl&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas;"&gt;&lt;a href="https://www.google.com/accounts/ClientLogin"&gt;&lt;span style="color: #555555;"&gt;https://www.google.com/accounts/ClientLogin&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-converted-space"&gt;&lt;span style="color: black; font-family: Consolas;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas;"&gt;-d Email=FOO@gmail.com -d "Passwd=FooPassWord" -d accountType=GOOGLE -d source=FOOServer -d service=ac2dm&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;[note this command is taken from comments posted on &lt;a href="http://blog.automated.it/"&gt;this&lt;/a&gt; blog]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-IwLTVIHdrBY/TaYcjjQLp8I/AAAAAAAADjQ/6HErRZansXE/s1600/C2DM_02_AuthToken.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="170" src="http://1.bp.blogspot.com/-IwLTVIHdrBY/TaYcjjQLp8I/AAAAAAAADjQ/6HErRZansXE/s400/C2DM_02_AuthToken.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Getting the auth token&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="apple-style-span"&gt;&lt;span style="color: black; font-family: Consolas; font-size: 10pt;"&gt;&lt;span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
This should give you few very long string values one of which would start with "Auth=". This is the one you want. Even if I have used curl here, it is recommended that you get the token&amp;nbsp;programmability, because even this token might change. If it changes, the new token would be returned as a response to the POST that we do to send the message.&lt;br /&gt;
&lt;br /&gt;
&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-E-9T_adxWfQ/TaYckj_qTdI/AAAAAAAADjY/ds2zaiYabyM/s1600/C2DM_04_SendMsg.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="474" src="http://2.bp.blogspot.com/-E-9T_adxWfQ/TaYckj_qTdI/AAAAAAAADjY/ds2zaiYabyM/s640/C2DM_04_SendMsg.png" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Sending the message&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I would like to thank Gabor Paller for writing a very good&lt;a href="http://mylifewithandroid.blogspot.com/2010/10/push-service-from-google.html"&gt; article&lt;/a&gt; on this and helping me with this process. Also, thanks to DavidMyton for his &lt;a href="http://blog.boxedice.com/2010/10/07/android-push-notifications-tutorial/"&gt;article&lt;/a&gt;. The comments below this article are pretty useful too. I also found &lt;a href="http://groups.google.com/group/android-c2dm/browse_thread/thread/3370e6fa9b90542b/d889956c87035bd3#d889956c87035bd3"&gt;this&lt;/a&gt; discussion on c2dm google group helpful.&lt;br /&gt;
&lt;br /&gt;
I have written this in a hurry. So let me know of any "bugs" in the article and I'll fix those &amp;nbsp;!!&lt;br /&gt;
Thank you !&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-670954279907474717?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/qDLLLMlwyt8FIUDnK8940uSxJgM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qDLLLMlwyt8FIUDnK8940uSxJgM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/qDLLLMlwyt8FIUDnK8940uSxJgM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/qDLLLMlwyt8FIUDnK8940uSxJgM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/uxh46ciQNPE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/670954279907474717/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2010/10/android-c2dm-messaging-server-push-for.html#comment-form" title="33 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/670954279907474717?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/670954279907474717?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/uxh46ciQNPE/android-c2dm-messaging-server-push-for.html" title="Android C2DM Messaging (Server Push for Android Phones)" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-DW9rE2FAmmY/TaYcjHK7YMI/AAAAAAAADjM/chc1NqHb8W8/s72-c/C2DM_01_signup.png" height="72" width="72" /><thr:total>33</thr:total><feedburner:origLink>http://techtej.blogspot.com/2010/10/android-c2dm-messaging-server-push-for.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CkAGRHk-eSp7ImA9Wx5UEUo.&quot;"><id>tag:blogger.com,1999:blog-3823876765206418073.post-3925311059211837757</id><published>2010-10-15T08:10:00.000-07:00</published><updated>2010-10-15T12:25:25.751-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2010-10-15T12:25:25.751-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="intellij" /><category scheme="http://www.blogger.com/atom/ns#" term="IDE" /><category scheme="http://www.blogger.com/atom/ns#" term="mobile development" /><category scheme="http://www.blogger.com/atom/ns#" term="command line tools" /><category scheme="http://www.blogger.com/atom/ns#" term="android" /><title>Using IntelliJ (or any IDE) with command line tools for developing Android projects</title><content type="html">&lt;span class="Apple-style-span"&gt;Recently&lt;/span&gt; I did some Blackberry development, and started using IntelliJ for that. I liked the concept of having the &lt;span class="Apple-style-span" style="font-size: medium;"&gt;IDE separate&lt;/span&gt; from the build environment. There is some extra work involved but it is convenient if you need a command line interface may be to automate your builds.&lt;br /&gt;
&lt;div&gt;Anyways jumping directly into the topic. I have here put together somethings you will need to do to use your choice of IDE and build using android command line tools. Since I have started liking to work with IntelliJ, I will also mention some IntelliJ specific tweaks.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So, clearly there are 2 parts here: The IDE set up and the build setup.&lt;/div&gt;&lt;div&gt;For build set up, we can just use the 'android' command to create the project. So, if we have a project in mind say TestProject, we'll create it using the command :&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;android create project --target 8 --name TestProject --path ./TestProject --activity TestActivity --package com.foo.Test&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: Georgia, serif; font-size: 16px;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;You can know the target by issuing the command :&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;android list target&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;I will not go deep into what are the targets and why you need them. You can find this information on the Android Developers Website.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;The create project command will generate a directory structure which will contain bunch of directories and some configuration files and the build.xml required by ant.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Before you create/import the project in your IDE, issue the "&lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;ant debug&lt;/span&gt;&lt;/span&gt;" command on this generated directory structure. This will generate the R.java file which is the resource file which is needed for compiling along with your source files.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;If you come from the Eclipse world, you know that there is a "workspace" in which there can be multiple "projects". Analogous to that, in IntelliJ, there is a "Project" in which there can be multiple "modules".&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Talking in terms of IntelliJ, create an empty project (without any modules).&lt;/div&gt;&lt;div&gt;Now, &lt;/div&gt;&lt;div&gt;- Click File -&amp;gt; New Module&lt;/div&gt;&lt;div&gt;- In the Add Module dialog, see that "Create module from scratch" is selected. Click next&lt;/div&gt;&lt;div&gt;- In the Content Root field, browse to the root of this project. The name field will automatically be updated. Click Next&lt;/div&gt;&lt;div&gt;- It will mark the TestProject/src  and the TestProject/gen directories as the source directories. This is what we want and this is why we ran the build process before creating the process. If you haven't run the build command before, it will only show the "src" directory. In that case, after you create the project, run the ant command and then come back to the module properties and mark the "gen" folder as a source folder. Doing this is important, or else it will never resolve the R.java  references and is quite frustrating.&lt;/div&gt;&lt;div&gt;- Click Next and then Finish.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now that we have added a new module, we'll need to add android libraries so that we can get intellicense !&lt;/div&gt;&lt;div&gt;- Right click on the module, go to Module Settings.&lt;/div&gt;&lt;div&gt;- Click on dependencies tab.&lt;/div&gt;&lt;div&gt;- Click Add -&amp;gt; Module Libraries&lt;/div&gt;&lt;div&gt;- Click Attach Jar Directories&lt;/div&gt;&lt;div&gt;- Select the specific android platform directory (that you used for creating the project with --target) For us that will be android-8 and will be located at &lt;span class="Apple-style-span" style="font-family: Verdana, sans-serif;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;${ANDROID_SDK}/platforms/android-8&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Select this path. Click OK twice. Click Apply.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;You are all set !! But wait. There is still a trick pending !&lt;/div&gt;&lt;div&gt;Any time you change any of the resource files, the R.java will be outdated. No issues while building, but the IDE will start cribbing. The Eclipse plugin takes care of updating th R.java. For IntelliJ or other IDEs it might be irritating to see those unresolved references. Not just irritating to see, but some IDEs constantly bug with pop ups for unresolved references. A common mistake will be to import the generic "android.R" package ! In this case, the "R" reference will be resolved but won't find any of user defined resources.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;So, each time when you add a resource, you'll need to build by issuing the ant command. But, many times the code is not complete and there is not point running the whole build. All we need is the command to generate the R.java file.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Simple, before writing any code, just run the ant command with the verbose output turned on. E.g.&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span"&gt; ant -v debug&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;In the -pre-build target, you will find the command for generating the R.java file. An example is as follows :&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-pre-build:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;-resource-src:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [echo] Generating R.java / Manifest.java from the resources...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] Current OS is Windows 7&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] Executing 'C:\android-sdk_r07-windows\android-sdk-windows\platforms\android-8\tools\aapt.exe' with arguments:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] 'package'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-f'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-m'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-M'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] 'C:\androidworkspace\TestProject\AndroidManifest.xml'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-S'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] 'C:\androidworkspace\TestProject\res'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-I'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] 'C:\android-sdk_r07-windows\android-sdk-windows\platforms\android-8\android.jar'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] '-J'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] 'C:\androidworkspace\TestProject\gen'&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] The ' characters around the executable and arguments are&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;     [null] not part of the command.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Now, all you need to do is extract and form command from this and put it in a batch file (or shell script) and whenever you add any resources, just run the batch file in order to generate the R.java&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;Hope this helps someone !&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3823876765206418073-3925311059211837757?l=techtej.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ac17hNNf-kvjFgZg99P4G4NfsfE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ac17hNNf-kvjFgZg99P4G4NfsfE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ac17hNNf-kvjFgZg99P4G4NfsfE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ac17hNNf-kvjFgZg99P4G4NfsfE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TechTej/~4/NnUBqZO_6PM" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://techtej.blogspot.com/feeds/3925311059211837757/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://techtej.blogspot.com/2010/10/using-intellij-or-any-ide-with-command.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3925311059211837757?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/3823876765206418073/posts/default/3925311059211837757?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/TechTej/~3/NnUBqZO_6PM/using-intellij-or-any-ide-with-command.html" title="Using IntelliJ (or any IDE) with command line tools for developing Android projects" /><author><name>Tejas</name><uri>http://www.blogger.com/profile/07649049782959178493</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://4.bp.blogspot.com/_BzJu3vX87n4/SgUP6mEyQeI/AAAAAAAAB9Y/2hHNNwEzPJs/S220/me.bmp" /></author><thr:total>0</thr:total><feedburner:origLink>http://techtej.blogspot.com/2010/10/using-intellij-or-any-ide-with-command.html</feedburner:origLink></entry></feed>

