<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Androidkit.com &#187; News</title>
	<atom:link href="http://www.androidkit.com/category/news/feed" rel="self" type="application/rss+xml" />
	<link>http://www.androidkit.com</link>
	<description>Android Development Blog</description>
	<lastBuildDate>Mon, 06 Sep 2010 05:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Loading Images from Remote Server over HTTP on a Separate Thread</title>
		<link>http://www.androidkit.com/loading-images-from-remote-server-over-http-on-a-separate-thread</link>
		<comments>http://www.androidkit.com/loading-images-from-remote-server-over-http-on-a-separate-thread#comments</comments>
		<pubDate>Fri, 28 May 2010 12:58:45 +0000</pubDate>
		<dc:creator>binil</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[developers]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=236</guid>
		<description><![CDATA[<p>by Binil Thomas</p>
<p>Whenever a user launches an Android application, a thread called &#8220;main&#8221; is automatically created. This main thread, also called the UI thread, is crucial since it’s responsible for dispatching events to various widgets, including the drawing events.&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>by Binil Thomas</p>
<p>Whenever a user launches an Android application, a thread called &#8220;main&#8221; is automatically created. This main thread, also called the UI thread, is crucial since it’s responsible for dispatching events to various widgets, including the drawing events. For careless Android developers, this single thread can be the overarching reason for poor app performance. With so much riding on a single thread performing long operations like network access or database queries, any interference on this thread will block up the entire user interface. No events can be dispatched – including drawing events – while long operations are underway, and from the user&#8217;s perspective, the application appears hung. Even worse, if the UI thread is blocked for more than a few seconds (about 5 seconds currently) the user will encounter the dreaded &#8220;application not responding&#8221; (ANR) dialog.</p>
<p>BaseAdapter is an Adapter object that acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to specific data points and is also responsible for making a View for each point in the data set. So, taking the example of downloading an image over HTTP, there may be some slowdown in our application with the Main UI thread getting blocked for more than a few seconds, and users might be presented with the ANR dialog. To avoid this situation I have some suggestions:</p>
<p>1. Use ExecuterService (Thread pool)<br />
2. Use AsynTask<br />
3. Use SoftReference Drawable Object<br />
4. Create the ListView first, then download images<br />
5. Make use of OnScrollListener Interface</p>
<p>I’ve written a sample application to help Android developers visualize this implementation.</p>
<p>Here we have AbastractListAdapter, an extension of BaseAdapterClass:</p>
<pre>public abstract class AbstactListAdapter extends BaseAdapter {
	public AbstactListAdapter(Context context) {
		this.context = context;
	}
	public abstract void setScrollStatus(boolean scroll);
	public abstract void scrollIdle(AbsListView view);
}</pre>
<p>There are two methods of implementation for Class ListAdapterScrollListener and Onscrollistner.</p>
<pre>public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {
		adapter.setScrollStatus(true);
	}
public void onScrollStateChanged(AbsListView view,intSrollState) {
		switch (scrollState) {
		case OnScrollListener.SCROLL_STATE_IDLE:
			adapter.scrollIdle(view);
			break;
		case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
			adapter.setScrollStatus(true);
			break;
		case OnScrollListener.SCROLL_STATE_FLING:
			adapter.setScrollStatus(true);
			break;
		}
}</pre>
<p>In my onCreate method I set up and configure the list view to load the views and set the listner for Scroll.</p>
<pre>public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Adapter mAdapter=new Adapter(this);
        setListAdapter(mAdapter);
        getListView().setOnScrollListener(new 		ListAdapterScrollListener(mAdapter));
      }</pre>
<p>I use an Adapter class to extend AbstractAdapterClass and implement BaseAdapter, both of which help to load images when scrolling is idle.</p>
<p>The image is loaded in a separate threadpool. I have used Executerservice and assign a threadpool to download images. This method employs a runnable which will extend Assigntask. This ImageLoader class has a subclass, workerthread, which extends Assyntask and implements runnables. This class uses ExecutorService, and assigns 5 threads to do the work. Other implementations of this kind launch a separate thread per image, meaning that the network connection will become clogged with any image load. Assigning the task to the workerthread subclass and using onprogressupdate to notify the adapter to display the image reduces the burden.</p>
<p>You’ll notice the use of SoftReference here. While this appears to work well, I haven’t done any significant load or performance testing, so it may not be necessary. Since bitmap/drawable objects require memory, and Android supports 16mb of heap, it’s better to classify those objects as SoftReference objects. SoftReferences pointing to softly reachable objects are guaranteed to be cleared before the VM triggers an OutOfMemoryError.  This can be written as follows:</p>
<pre> public class ImageLoader {

private class WorkerThread extends AsyncTask implements Runnable{
		public WorkerThread(String url,int pos) {
			this.url=url;
			intex=pos;
			}
		@Override
		protected void onProgressUpdate(Void... values) {
			mAdapter.notifyDataSetChanged();
			super.onProgressUpdate(values);
		}
		@Override
		public void run() {
			Cache.put(intex,new SoftReference(readDrawableFromNetwork(this.url)));
			publishProgress();
		}
	}

	public Drawable getDrawble(int pos)
	{
		SoftReference mReference=Cache.get(pos);;
		if(mReference!=null)
			return mReference.get();
		else
			return null;
	}

/*method to get Image if already or to start new task to download*/
	public void loadImage(int First,int Last) {
			try{
					_exec = Executors.newFixedThreadPool(5);
				for(int pos=First;pos&lt;=Last;pos++){
					if(Cache.containsKey(pos)){
						if(Cache.get(pos).get()==null)
							_exec.execute(new  WorkerThread(Dataset.mStrings[pos],pos));
					}else{
						_exec.execute(new  WorkerThread(Dataset.mStrings[pos],pos));
					}
				}
			}catch (Exception e) {
				_exec.shutdown();
			}

	}//end of method

	private static Drawable readDrawableFromNetwork(String url ) {
	   Write code here to downlaod image from network.
	}//end of method
}</pre>
<p>And that’s it!</p>
<p>For your reference, the code has been packaged for you to download and inspect <a href="http://www.androidkit.com/wp-content/uploads/2010/05/ImageDownload.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/loading-images-from-remote-server-over-http-on-a-separate-thread/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AndroidBook Now available in Android Market</title>
		<link>http://www.androidkit.com/androidbook-now-available-in-android-market</link>
		<comments>http://www.androidkit.com/androidbook-now-available-in-android-market#comments</comments>
		<pubDate>Fri, 28 Aug 2009 14:11:46 +0000</pubDate>
		<dc:creator>rohit</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Sourcebits]]></category>
		<category><![CDATA[Facebook App for Android]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=213</guid>
		<description><![CDATA[<p><a href="http://www.cyrket.com/package/com.sourcebits.androidbook">AndroidBook</a> after a month of intensive bug fixing sessions is again available in Android Market. We are sure there are few more bugs that we need to fix, but we did not want our users to keep on waiting. Rest&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cyrket.com/package/com.sourcebits.androidbook">AndroidBook</a> after a month of intensive bug fixing sessions is again available in Android Market. We are sure there are few more bugs that we need to fix, but we did not want our users to keep on waiting. Rest assured, this build is far far better then the last one we put up in the Android Market. We look forward to your feedback and comments on this build.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/androidbook-now-available-in-android-market/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ADC 2 is here to rock the world of Android Developers again!</title>
		<link>http://www.androidkit.com/adc-2-is-here-to-rock-the-world-of-android-developers-again</link>
		<comments>http://www.androidkit.com/adc-2-is-here-to-rock-the-world-of-android-developers-again#comments</comments>
		<pubDate>Thu, 28 May 2009 11:53:16 +0000</pubDate>
		<dc:creator>Shesh</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA["Developers Challenge" ADC "ADC 2"]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=151</guid>
		<description><![CDATA[<p><a title="AndroidKit - ADC 2" href="http://code.google.com/android/adc/" target="_blank">ADC 2</a> has been announced at the Google site. When Android was announced on 5 November, 2007, Google also announced a $10 million Android Developer Challenge, split into two separate $5 million events. ADC 1 with a $5 million prize&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><a title="AndroidKit - ADC 2" href="http://code.google.com/android/adc/" target="_blank">ADC 2</a> has been announced at the Google site. When Android was announced on 5 November, 2007, Google also announced a $10 million Android Developer Challenge, split into two separate $5 million events. ADC 1 with a $5 million prize money attracted 1700 entries and 50 winners. <a title="AndroidKit - ADC 2" href="http://code.google.com/android/adc/" target="_blank">ADC 2</a> has a prize kitty of $1,925,000 split amongst 30 winners . Can we expect an ADC 3 for the remaining $3,075,000 ?.</p>
<p>Compared to investments of Apple, which has a $100 million fund to seed iPhone applications, and RIM, which has $150 million fund to seed Blackberry applications, the Google investment is a far cry away.</p>
<p>Judging for ADC 2 is different from ADC 1 in that there will be 30 winners against the 50 last year, and 45% of weightage for an application is decided by the community vote and 55% by the judges.<br />
It is mandatory to submit applications that run on Android 1.5 and be in English, and those that are unpublished and non-upgraded.</p>
<p>ADC2 will have two rounds of judging, the first round results in 200 apps total(in 10 categories), that will proceed to the second round. Out of which 30 entries will be winners with 3 entries within the 30 picking up the prizes in the overall winners category.</p>
<p>The contest is expected to start in August 09 and winning entries declared by November 09. We could see a drop in the Android market uploads, as the opportunity cost of waiting is pretty high. We could also see a host of entries in the Lite version (Full-featured with expiry time), so popular applications could potentially rake in money in both places (ADC 2 and The Android Market).</p>
<p>One bone of contention is the &#8216;Supposed ban on Open Source apps &#8216; <a title="AndroidKit - ADC 2" href="http://andblogs.net/2009/05/adc2-announced-but-theres-a-catch/comment-page-1/" target="_blank">My comments</a> here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/adc-2-is-here-to-rock-the-world-of-android-developers-again/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Early experience with the Android 1.5 SDK</title>
		<link>http://www.androidkit.com/early-experience-with-the-android-15-sdk</link>
		<comments>http://www.androidkit.com/early-experience-with-the-android-15-sdk#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:06:51 +0000</pubDate>
		<dc:creator>Shesh</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=143</guid>
		<description><![CDATA[<p>The <a title="AndroidKit" href="http://developer.android.com/sdk/1.5_r1/index.html" target="_blank">Android 1.5 SDK r1</a> has been released by the Google team and it was hardly any wait from the early look SDK that came out 2 weeks ago.<br />
Of course, the feature-set mentioned in the&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>The <a title="AndroidKit" href="http://developer.android.com/sdk/1.5_r1/index.html" target="_blank">Android 1.5 SDK r1</a> has been released by the Google team and it was hardly any wait from the early look SDK that came out 2 weeks ago.<br />
Of course, the feature-set mentioned in the beta is there, and the documentation is updated.</p>
<p>More details on <a title="AndroidKit" href="http://developer.android.com/guide/developing/tools/avd.html" target="_blank">creation of AVDs</a> and <a title="AndroidKit" href="http://developer.android.com/sdk/android-1.5.html" target="_blank">version notes</a> detailing the usage of minSDKVersion for developers.</p>
<p>Compiling our source with a build target of 1.1, went smoothly and hardly any change in code was needed for a build target of 1.5. However, moving to build target of Android 1.5 would not suffice for a project that used Maps, we had to select the &#8216;Google APIs&#8217; build target (understandable as the maps package was moved out).  Respective Deployment targets were selected for running the apk in the emulator.</p>
<p>It was a joy to see the soft-keys come up when I hit the text box, I have to admit!.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/early-experience-with-the-android-15-sdk/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android 1.5 Early Look SDK released</title>
		<link>http://www.androidkit.com/android-15-early-look-sdk-released</link>
		<comments>http://www.androidkit.com/android-15-early-look-sdk-released#comments</comments>
		<pubDate>Wed, 15 Apr 2009 09:22:41 +0000</pubDate>
		<dc:creator>Shesh</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA["Android 1.5"]]></category>
		<category><![CDATA[Cupcake]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=123</guid>
		<description><![CDATA[<p>Touted to power the next Android device, aka &#8220;Android on Steroids&#8221;, the Android Developer Blog has announced the early release of the <a title="AndroidKit" href="http://developer.android.com/sdk/preview/" target="_blank">Android 1.5 SDK</a> ,  which is to be released in its complete glory, to its&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Touted to power the next Android device, aka &#8220;Android on Steroids&#8221;, the Android Developer Blog has announced the early release of the <a title="AndroidKit" href="http://developer.android.com/sdk/preview/" target="_blank">Android 1.5 SDK</a> ,  which is to be released in its complete glory, to its developers, at the end of the month. For the time being, developers can get-a-hang of the new API, which is drawn from the <a title="AndroidKit" href="http://source.android.com/" target="_blank">Cupcake</a> branch of the Android Open Source project.</p>
<p>Prominent features of the new SDK are :<br />
Speech Recognition, Soft keyboard, Improved accelerometer and Video recording and uploading capability.<br />
A complete list of the <a title="AndroidKit" href="http://developer.android.com/sdk/preview/features.html" target="_blank">Android 1.5 Highlights</a>.</p>
<p>The biggest improvement from a developers perspective is the AVD Concurrency. Developers can now create Android Virtual Devices with different names and work with emulators in parallel. Also, the choice of multiple targets (including Android 1.1 and Android 1.5), means that developers can continue to test their compilations for older targets (1.1 and earlier), but the catch is, you lose network connectivity (known issue in this SDK). So if you are developing an application which uses network access, then you have to wait for the release version of Android 1.5 SDK.</p>
<p>Eclipse developers, will have to uninstall the ADT 0.8 plugin and install the ADT 0.9 plugin to make use of the new SDK.</p>
<p>It is not yet clear if the team has enhanced the code to handle errors such as &#8211; memory overrun that needs &#8216;bitmap recycle&#8217; and &#8216;audio flinger &#8216; when looping sound files, atleast in this release.</p>
<p>For the user, however, the question remains how far the G1 will continue. With the 1.5 SDK onslaught, we are definitely looking at a G3 (as per the API Level). There are inherent limitations to firmware upgrades, as it needs a supporting underlying hardware. Also, with the addition of the soft keypad, can we expect the new device be thinner ?</p>
<p>The G1 device certainly needs more RAM (55MB ? come on guys &#8211; the iPhone 3G will have 128MB, what is Google thinking?)</p>
<p>But for now, it is hoping for rosy days ahead for our favourite platform &#8211; Android.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/android-15-early-look-sdk-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
