<?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; Applications</title>
	<atom:link href="http://www.androidkit.com/category/applications/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>Writing Portable Android Applications</title>
		<link>http://www.androidkit.com/writing-portable-android-applications</link>
		<comments>http://www.androidkit.com/writing-portable-android-applications#comments</comments>
		<pubDate>Wed, 21 Apr 2010 02:45:33 +0000</pubDate>
		<dc:creator>cary</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[developers]]></category>
		<category><![CDATA[handset differentiation]]></category>
		<category><![CDATA[screen resolution]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=218</guid>
		<description><![CDATA[<p><strong>(Binil Thomas)</strong></p>
<p>Anyone with significant time in mobile application development understands the challenges of writing portable applications. There are tons of reasons for this, but probably the biggest hurdles we face are:</p>
<ul>
<li>Varying screen sizes</li>
<li>Varying screen resolutions</li>
<li>Varying</li></ul><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><strong>(Binil Thomas)</strong></p>
<p>Anyone with significant time in mobile application development understands the challenges of writing portable applications. There are tons of reasons for this, but probably the biggest hurdles we face are:</p>
<ul>
<li>Varying screen sizes</li>
<li>Varying screen resolutions</li>
<li>Varying hardware configurations</li>
<li>Varying media formats; such as for images, audio, video</li>
<li>Varying input methods; e.g. touch screen, T9 key pad, qwerty keypad</li>
<li>Non-standard, device-specific hardware keys</li>
</ul>
<p>And so on and so forth &gt;_&lt;</p>
<p>Android engineers, anticipating the witches brew of OEM handsets they would encounter, took steps to try and alleviate the situation by standardizing some key features:</p>
<ul>
<li>A very rich widget set that can scale according to needs</li>
<li>Standardized way of implementing custom widgets</li>
<li>Standardized user interface conventions for touch screen devices</li>
<li>Standardized image capture formats {still buggy from time to time}</li>
<li>Standardized mechanism for sharing code across different components; such as user interface elements, fixed content or a specific activity</li>
<li>Standardized on a base set of hardware keys; e.g. Home, Back, End, and Trackball</li>
</ul>
<p>Above notwithstanding, with screen sizes and resolutions still very much device dependent {see: <a href="http://www.t-mobileg1.com/">T-Mobile G1</a>, <a href="http://www.motorola.com/Consumers/US-EN/Consumer-Product-and-Services/Mobile-Phones/Motorola-DROID-US-EN?localeId=33 ">Motorola Droid</a>, <a href="http://www.google.com/phone/?hl=en&amp;s7e=">Google Nexus One</a>, HTC Hero and so on}, creating a consistent UI that both looks good and works well on all platforms has been a slog. For Android developers or those just interested in Android application development, here we present a method and a design pattern that can be utilized to achieve precisely that. The focus points are as follows:</p>
<ul>
<li>Understand the functionality that needs to be replicated per device. This can be represented by a Java interface to achieve, for example, scaled UI elements across varying screen sizes and resolutions.</li>
<li>Separate device-specific features into device-specific implementations. For example, each phone {including from the same manufacturer} might have different hardware keys, or even different keypads (such as T9, QWERTY, or SureType). If an application is to work on different phones with different input mechanisms, it must take into account these differences when implementing.</li>
<li>A Class Factory that can intelligently instantiate the device-specific components of multiple handset designs.</li>
</ul>
<p>Let’s take for example the case of displaying a splash screen at application launch. Here we address the issue of supporting for multiple devices. The first act of separating the functionality begins with this interface:</p>
<pre>

public interface SplashableScreen {
<p style="padding-left: 30px;">public void showSplashImage(ImageView mView);
<p style="padding-left: 30px;">public void startSpalshing() throws Exception;
<p style="padding-left: 30px;">public void SetSplashDuration(int time);

}
</pre>
<p>Any screen that can be shown as a splash has the functionality as described by the methods indicated.</p>
<p>A device-specific implementation / screen-specific implementation can be written as follows:</p>
<pre>

public class SplashScrren_320_480 implements SplashableScreen{
<p style="padding-left: 30px;">public void showSplashImage(ImageView mView){
<p style="padding-left: 60px;">// Write code speficic to this resolution.
<p style="padding-left: 30px;">}

}
</pre>
<p>And a proper implementation can be instantiated and used as follows:</p>
<pre>
<p style="padding-left: 30px;">public class SplashFactory{
<p style="padding-left: 60px;">public static SplashableScreen getSplashScreen(){
<p style="padding-left: 60px;">// Given a device metrics, instantiate appropriate class and return.
<p style="padding-left: 60px;">}
<p style="padding-left: 30px;">}
</pre>
<p>We’re pleased to offer the full code for this useful application for download <a href="http://www.androidkit.com/wp-content/uploads/2010/04/SplashScreen.zip" target="_self">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/writing-portable-android-applications/feed</wfw:commentRss>
		<slash:comments>2</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>Signing your Android Application</title>
		<link>http://www.androidkit.com/signing-your-android-application</link>
		<comments>http://www.androidkit.com/signing-your-android-application#comments</comments>
		<pubDate>Fri, 03 Apr 2009 08:01:10 +0000</pubDate>
		<dc:creator>Shesh</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Android Signing]]></category>

		<guid isPermaLink="false">http://www.androidkit.com/?p=85</guid>
		<description><![CDATA[<p><span style="color: #00ffbf;"><strong>Generating Your Own Key:</strong></span></p>
<p>If you wish to publish your application to other users, you are required to sign your application with your own personal certificate. You can generate your own certificate by using the keytool.exe that comes with the&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #00ffbf;"><strong>Generating Your Own Key:</strong></span></p>
<p>If you wish to publish your application to other users, you are required to sign your application with your own personal certificate. You can generate your own certificate by using the keytool.exe that comes with the JDK/bin folder. In most cases, you can tell the SDK build tools how to find keytool by making sure that your JAVA_HOME environment variable is set and that it references a suitable JDK. Alternatively, you can add the JDK version of Keytool to your PATH variable.</p>
<p>To generate your own certificate, issue the following command:</p>
<pre>keytool –genkey –v –keystore sourcebits.keystore –alias CoolApp –keyalg RSA –validity 10000</pre>
<p>The above command generates a certificate named sourcebits.keystore with the key alias sourcebits, generated using the RSA algorithm, and with a validity of 10,000 days (this is the minimum recommended).</p>
<p>You will be prompted for some information:</p>
<p>What is your first and last name?</p>
<p>[unknown]: &lt;enter your first and last name&gt;</p>
<p>What is the name of your organizational unit?</p>
<p>[unknown]: &lt;enter your organizational unit&gt;</p>
<p>What is the name of your organization?</p>
<p>[unknown]: &lt;enter the name of your company&gt;</p>
<p>What is the name of your City or Locality?</p>
<p>[unknown]: &lt;enter the name of your city&gt;</p>
<p>What is the name of your State or Province?</p>
<p>[unknown]: &lt;enter the name of your state&gt;</p>
<p>What is the two-letter country code for this unit?</p>
<p>[unknown]: &lt;enter the two digit country code&gt; e.g for USA it is US.</p>
<p>If you are publishing your application for the Android Market, your keystore must have a validity period that ends after 22 October 2033 (which is the reason greater than 10000 days validity is recommended).</p>
<p>Keytool prompts you to provide passwords for the keystore and key.  It then generates the keystore as a file called sourcebits.keystore. The keystore and key are protected by the passwords you entered. The keystore contains a single key, valid for 10000 days. The alias is a name that you — will use later, to refer to this keystore when signing your application. Secure and protect these two passwords so that only people who are authorized to sign your applications know about them.</p>
<p><span style="color: #00ffbf;"><strong>Signing your Android application:</strong></span></p>
<p>All Android applications must be signed before they are allowed to be deployed onto a device.  Android Market Place has made it mandatory to at-least Self-Sign your app before it is accepted. Unlike other mobile platforms, you need not purchase digital certificates from a certificate authority (CA). Instead, you can self-sign (generate your own personal certificate and use it to sign your Android applications).</p>
<p><strong><span style="color: #00ffbf;">To sign your application manually:</span></strong></p>
<p>Have a project that generates your executable with the name you desire for your application.</p>
<p><strong><span style="color: #00ffbf;">(PAIN POINT: Your signing may fail otherwise). </span></strong></p>
<p>Go to Eclipse, right-click on the project -&gt;Android Tools-&gt;Export Unsigned Application Package and Select the apk file. You will then be asked to select a directory for exporting the application. For convenience you can export the Android package (with the .apk extension) to JDK/bin.</p>
<pre>jarsigner -verbose -keystore sourcebits.keystore CoolApp.apk CoolApp</pre>
<p>When prompted for the password for the keystore, use the password that was supplied during the key generation.</p>
<p>To verify that the application is signed correctly, you can use the –verify option with jarsigner.exe.</p>
<p>To verify that your .apk is signed, you can use a command like this:</p>
<pre>$ jarsigner -verify CoolApp.apk</pre>
<p>If the .apk is signed properly, Jarsigner prints &#8220;jar verified&#8221;. If you want more details, you can try one of these commands:</p>
<pre>$ jarsigner -verify -verbose CoolApp.apk</pre>
<p>or</p>
<pre>$ jarsigner -verify -verbose -certs CoolApp.apk</pre>
<p>The command above, with the –certs option added, the details of the certificate used to sign the application can be seen.</p>
<p><span style="color: #00ffbf;">NOTE:</span></p>
<p>Select strong passwords for the keystore and key.</p>
<p>When you use keytool and jarsigner, <em>do not</em> supply the -storepass and -keypass options at the command line</p>
]]></content:encoded>
			<wfw:commentRss>http://www.androidkit.com/signing-your-android-application/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
