<?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>Brain Friendly Code</title>
	<atom:link href="http://devaxis.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://devaxis.com</link>
	<description>Software Development Techniques</description>
	<lastBuildDate>Tue, 31 Aug 2010 06:49:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How To Stop Multiple Instances For An Activity</title>
		<link>http://devaxis.com/google/android/how-to-stop-multiple-instances-for-an-activity/</link>
		<comments>http://devaxis.com/google/android/how-to-stop-multiple-instances-for-an-activity/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 04:29:45 +0000</pubDate>
		<dc:creator>rashid</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Multiple Instances for Activity]]></category>
		<category><![CDATA[Single Task Launch Mode]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[Timer Task]]></category>

		<guid isPermaLink="false">http://devaxis.com/?p=6</guid>
		<description><![CDATA[To make visible an activity that is already running or to create an activity that is not currently running, add android:launchMode=&#8221;singleTask&#8221; in activity element in AndroidManifest.xml. For example an activity &#8220;SingleTaskActivity&#8221; for that we want to stop multiple instances, its entry in &#8220;AndroidManifest.xml&#8221; is as; &#60;manifest&#62; --------------------------------------------------------------------- &#60;activity android:name=".SingleTaskActivity" android:launchMode="singleTask" android:label="@string/app_name"&#62; &#60;/activity&#62; -------------------------------------------------------------------- &#60;/manifest&#62; Here is a [...]]]></description>
			<content:encoded><![CDATA[<p>To make visible an activity that is already running or to create an activity that is not currently running, add <strong>android:launchMode=&#8221;singleTask&#8221;</strong> in <strong>activity element</strong> in <strong>AndroidManifest.xml.</strong></p>
<p>For example an activity &#8220;SingleTaskActivity&#8221; for that we want to stop multiple instances, its entry in &#8220;AndroidManifest.xml&#8221; is as;</p>
<pre>

&lt;manifest&gt;

---------------------------------------------------------------------

&lt;activity android:name=".SingleTaskActivity"
android:launchMode="singleTask"
android:label="@string/app_name"&gt;
&lt;/activity&gt;

--------------------------------------------------------------------

&lt;/manifest&gt;
</pre>
<p><span id="more-6"></span></p>
<p>Here is a complete working example;</p>
<p>src&gt;com.devaxis.apis:</p>
<p>I have created two classes<strong> HomeActivity.java</strong> and <strong>SingleTaskActivity.java.</strong></p>
<p>HomeActivity.java</p>
<pre>

public class HomeActivity extends Activity {
private static final long DEFAULT_DELAY = 5000;
private static final long DEFAULT_PERIOD = 5000;
private Handler handler;
private Timer timer;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

timer = new Timer();
handler = new Handler();

// Schedule a task to start activity for repeated fixed-rate execution after 5 seconds.
startSingleTaskActivity(DEFAULT_DELAY,DEFAULT_PERIOD);
}
public void onBackPressed ()
{
timer.cancel();
finish();
}

public void startSingleTaskActivity(long delay,long period)
{
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
startActivity(new Intent(HomeActivity.this, SingleTaskActivity.class));
}
});
}
};
timer.scheduleAtFixedRate(timerTask, delay,period);
}
}
</pre>
<p>In HomeActivity.java A Timer with TimerTask is used to schedule a task to start activity for repeated fixed-rate execution after 5 seconds.</p>
<p>SingleTaskActivity.java</p>
<pre>

public class SingleTaskActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_task_activity);
}
}
</pre>
<p>res&gt;layouts:</p>
<p>main.xml</p>
<pre>

&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;&lt;a href=&quot;http://schemas.android.com/apk/res/android&quot;&gt;http://schemas.android.com/apk/res/android&lt;/a&gt;&quot;
android:orientation=&quot;vertical&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
&amp;gt;
&amp;lt;TextView
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:textStyle = &quot;bold&quot;
android:text=&quot;@string/home_activity_label&quot;
/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;

single_task_activity.xml

&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;LinearLayout xmlns:android=&quot;&lt;a href=&quot;http://schemas.android.com/apk/res/android&quot;&gt;http://schemas.android.com/apk/res/android&lt;/a&gt;&quot;
android:orientation=&quot;vertical&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;fill_parent&quot;
&amp;gt;
&amp;lt;TextView
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:textStyle = &quot;bold&quot;
android:text=&quot;@string/single_task_activity_label&quot;
/&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
</pre>
<p>res&gt;values:</p>
<p>strings.xml</p>
<pre>

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
&lt;string name="home_activity_label"&gt;Home Activity!&lt;/string&gt;
&lt;string name="app_name"&gt;Stop Multiple Activity Instances&lt;/string&gt;
&lt;string name="single_task_activity_label"&gt;Single Task Activity!&lt;/string&gt;
&lt;/resources&gt;
</pre>
<p>AndroidManifest.xml</p>
<pre>

&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;
&amp;lt;manifest xmlns:android=&quot;&lt;a href=&quot;http://schemas.android.com/apk/res/android&quot;&gt;http://schemas.android.com/apk/res/android&lt;/a&gt;&quot;
package=&quot;com.devaxis.apis&quot;
android:versionCode=&quot;1&quot;
android:versionName=&quot;1.0&quot;&amp;gt;
&amp;lt;application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;&amp;gt;
&amp;lt;activity android:name=&quot;.HomeActivity&quot;
android:label=&quot;@string/app_name&quot;&amp;gt;
&amp;lt;intent-filter&amp;gt;
&amp;lt;action android:name=&quot;android.intent.action.MAIN&quot; /&amp;gt;
&amp;lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&amp;gt;
&amp;lt;/intent-filter&amp;gt;
&amp;lt;/activity&amp;gt;
&amp;lt;activity android:name=&quot;.SingleTaskActivity&quot;
android:launchMode=&quot;singleTask&quot;
android:label=&quot;@string/app_name&quot;&amp;gt;
&amp;lt;/activity&amp;gt;
&amp;lt;/application&amp;gt;
&amp;lt;/manifest&amp;gt;
</pre>
<p>Download complete source codeNote: There is a file embedded within this post, please visit this post to download the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://devaxis.com/google/android/how-to-stop-multiple-instances-for-an-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Knowledge And Skill For All</title>
		<link>http://devaxis.com/general/knowledge-and-skill-for-all/</link>
		<comments>http://devaxis.com/general/knowledge-and-skill-for-all/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 08:21:02 +0000</pubDate>
		<dc:creator>rashid</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[Skill]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://devaxis.com/?p=3</guid>
		<description><![CDATA[Knowledge is light. It is the most important weapon for development in life.The power of knowledge leads us to ultimate success. Let&#8217;s enlighten it to remove the darkness of ignorance by share our knowledge,skill and talent.]]></description>
			<content:encoded><![CDATA[<p>Knowledge is light. It is the most important weapon for development in life.The power of knowledge leads us to ultimate success.</p>
<p>Let&#8217;s enlighten it to remove the darkness of ignorance by share our knowledge,skill and talent.</p>
]]></content:encoded>
			<wfw:commentRss>http://devaxis.com/general/knowledge-and-skill-for-all/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

