<?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>David J KelleyDavid J Kelley</title>
	<atom:link href="http://davidjkelley.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://davidjkelley.net</link>
	<description>My Professional &#38; Personal Online Presence</description>
	<lastBuildDate>Wed, 06 Feb 2013 15:37:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>AsyncLogin Eclipse Project Files</title>
		<link>http://davidjkelley.net/?p=117</link>
		<comments>http://davidjkelley.net/?p=117#comments</comments>
		<pubDate>Wed, 06 Feb 2013 15:35:58 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Guides/Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=117</guid>
		<description><![CDATA[Due to high demand, I have attached the source project files for this little app! See here: BothAsyncLogins]]></description>
			<content:encoded><![CDATA[<p>Due to high demand, I have attached the source project files for this little app! See here:<br />
<a href='http://davidjkelley.net/wp-content/uploads/2013/02/BothAsyncLogins.zip'>BothAsyncLogins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=117</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Newspapers&#8217; Folly</title>
		<link>http://davidjkelley.net/?p=110</link>
		<comments>http://davidjkelley.net/?p=110#comments</comments>
		<pubDate>Mon, 22 Oct 2012 09:36:55 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[21st Century Polling]]></category>
		<category><![CDATA[Politics]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=110</guid>
		<description><![CDATA[To young Americans, newspapers are a dying medium. We don’t necessarily have a set of reasons – only a pragmatic recognition of the smartphone’s dominance in our personal and professional lives. As a young professional, finding time to read a newspaper is rare – practically the only time being that calm period when everyone is [...]]]></description>
			<content:encoded><![CDATA[<p>	To young Americans, newspapers are a dying medium. We don’t necessarily have a set of reasons – only a pragmatic recognition of the smartphone’s dominance in our personal and professional lives.</p>
<p>	As a young professional, finding time to read a newspaper is rare – practically the only time being that calm period when everyone is grumbling about taxiing and waiting in line to depart prior to a flight. I  (and I suspect many of my twenty-something business professional cohorts would also cop-out to after a bit of coaxing) relish this stopgap period.  The stewardess asks if I would like a newspaper – and while I reluctantly accept – the back of my mind says ‘I wonder what these things are up to these days!’</p>
<p>	Sure enough, the quality of the columns, the precision of argument, the scope of topic – all remains untouched by specialty news and blogs based solely or largely online. After only a five-minute period, perhaps two articles, I immediately realize that the only reason newspapers are dying medium? Because I won’t give them a second glance &#8211; because I won’t devote time to them. Not to labor the point, but at the same time I grumble about the lack of in-depth, solid, accountable, piercing journalism at the electronic sources I regularly visit – I actively ignore the medium through which these journalistic endeavors continue to persist, if slightly less powerfully than in past eras. </p>
<p>	Yet newspapers find themselves playing to the same counter-productive dividing lines of American politics as any other news source, including online.</p>
<p>	Two articles within the same page of the International Tribune, highlight this perfectly (watch as your political biases flash alive for the first time): Triumph of the wrong?  by Paul Krugman and The generation war by David Brooks (let’s ignore the third useless dividing line – age).  Krugman speaks of the folly of modern American politics in which the most contradictory views of the modern Republican Party ‘Keep your government hands off my Medicare!’ controls the pragmatic and reasonable elements of the Grand Old Party without ever mentioning the distinction and instead burns the bridges of compromise. In his own article, Brooks speaks as a Conservative who has openly mourned the loss of reasonable Republicans, and can even be heard in this very article saying, “He took it to Representative Paul Ryan on the inexplicability of the Republican tax plan.” Lest we be in-equal: Brooks takes his time to line up enough across the bow shots at the party with which he does not identify as well.</p>
<p>	Two sides, speaking past each other. There are less-than-moderate elements to each party. Heck, there are more than two parties (a topic, like age, for another article). But only one party recently won a wave election, running nearly 130 Tea Party candidates. You don’t see democratic socialists (save Bernie) or Greens carrying the party mantle the way Eric Cantor enthusiastically supports and links the Tea Party agenda to that of the Republican Party, and you certainly don’t see the Arlen Spector’s of yesterday’s Republican Party any longer. Compromise is no longer possible.</p>
<p>	Perhaps some of it is due to each party, perhaps some of the lack of compromise is due to feckless representatives refusing to have a drink, or inviting for a drink, a member across the aisle. </p>
<p>	But to speak past each other in the public sector? We do not need the Democratic soapbox on the left-hand corner of the street and the Republican soapbox on the right-hand street corner. I send my representatives to Washington DC to vote and compromise. I do not send my representatives to fall over and give in to people with different principles and opinions. Something tells me Mr. Krugman and Mr. Brooks feel quite similar. </p>
<p>	How shall we get back to a point where our representatives can work together, when the talking heads on the closest thing we have in America to the ‘Fourth Estate’ are too busy extolling opinion like this, “It will be the crowning irony of the No Drama Obama campaign that it took a man who exudes more drama than a decade of Latin American soap operas to get Democrats out of their funk” [Brooks]? While Krugman’s article at least is based on an IMF document, rather than solely opinion, in his standard dry humor, “ And what this analysis concludes is that a disproportionate share of the bad news is coming from countries pursuing the kind of austerity policies Republicans want to impose on America.” </p>
<p>	Perhaps Paul and David would better serve American political discourse if they sat down, had a drink, and came up with something logical that they agree on and think can be done – then publish that, preferably with a random probability determining whose name is placed first.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=110</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting If a User is Logged In; Detecting Other SQL Attributes</title>
		<link>http://davidjkelley.net/?p=91</link>
		<comments>http://davidjkelley.net/?p=91#comments</comments>
		<pubDate>Thu, 24 May 2012 22:54:30 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[21st Century Polling]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Guides/Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=91</guid>
		<description><![CDATA[Detecting if the user is logged in is an important aspect of how the UI functions and what it should look like. Here&#8217;s a snippet of my AsyncTask that helps load questions from my SQL db: protected Integer doInBackground&#40;String... params&#41; &#123; DatabaseHandler dbHandler = activity.getDB&#40;&#41;; questionList = userFunctions.getQuestions&#40;category&#41;; &#160; for &#40;int j = 0; j [...]]]></description>
			<content:encoded><![CDATA[<p>Detecting if the user is logged in is an important aspect of how the UI functions and what it should look like. Here&#8217;s a snippet of my AsyncTask that helps load questions from my SQL db:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Integer</span> doInBackground<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		DatabaseHandler dbHandler <span style="color: #339933;">=</span> activity.<span style="color: #006633;">getDB</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		questionList <span style="color: #339933;">=</span> userFunctions.<span style="color: #006633;">getQuestions</span><span style="color: #009900;">&#40;</span>category<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> questionList.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//run up the list of JSON objects</span>
				<span style="color: #666666; font-style: italic;">//check if the user is logged in AND has answered the question previously, mark each JSON object appropriately</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userFunctions.<span style="color: #006633;">hasUserAnswered</span><span style="color: #009900;">&#40;</span>questionList.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span>, dbHandler.<span style="color: #006633;">getUserDetails</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					questionList.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;result&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
					questionList.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;result&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> questionList.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPostExecute<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> numQuestions<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> questionList.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			JSONObject question<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				question <span style="color: #339933;">=</span> questionList.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userFunctions.<span style="color: #006633;">isUserLoggedIn</span><span style="color: #009900;">&#40;</span>activity<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					DatabaseHandler dbHandler <span style="color: #339933;">=</span> activity.<span style="color: #006633;">getDB</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #666666; font-style: italic;">//ensure again the user is logged in, then run the method to populate the question (second param determines how it will look on screen)</span>
					fragment.<span style="color: #006633;">buildQuestions</span><span style="color: #009900;">&#40;</span>question, question.<span style="color: #006633;">getBoolean</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;result&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		progressRow.<span style="color: #006633;">setVisibility</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span>.<span style="color: #006633;">GONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And here&#8217;s how buildQuestions() looks (remember to look at the second boolean parameter and how it&#8217;s used in conditionals inside the method):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> buildQuestions<span style="color: #009900;">&#40;</span>JSONObject question, <span style="color: #000066; font-weight: bold;">boolean</span> isAnswered<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JSONException <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isAnswered<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			questionContainer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TableLayout<span style="color: #009900;">&#41;</span> layout.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">questionContainer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">View</span> questionBox <span style="color: #339933;">=</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">question</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			questionBox.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			TextView title <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">questionTextView</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			title.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Answered: &quot;</span> <span style="color: #339933;">+</span> question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">Button</span> chartsButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">chartsButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			chartsButton.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>question<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Button</span> submitButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">submitButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			chartsButton.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span>chartsListener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//submitButton.setOnClickListener(submitListener);</span>
			submitButton.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Submitted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			submitButton.<span style="color: #006633;">setClickable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			TableRow tr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TableRow<span style="color: #009900;">&#41;</span> questionBox<span style="color: #339933;">;</span>
			TableLayout.<span style="color: #006633;">LayoutParams</span> trParams <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TableLayout.<span style="color: #006633;">LayoutParams</span><span style="color: #009900;">&#40;</span>
					TableLayout.<span style="color: #006633;">LayoutParams</span>.<span style="color: #006633;">MATCH_PARENT</span>,
					TableLayout.<span style="color: #006633;">LayoutParams</span>.<span style="color: #006633;">MATCH_PARENT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			trParams.<span style="color: #006633;">setMargins</span><span style="color: #009900;">&#40;</span>leftMargin, topMargin, rightMargin, bottomMargin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//tr.setLayoutParams(trParams);</span>
			tableList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			questionContainer.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			TagObj tagObj <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TagObj<span style="color: #009900;">&#40;</span>question, radioGroup, tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			submitButton.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>tagObj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			questionContainer <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TableLayout<span style="color: #009900;">&#41;</span> layout.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">questionContainer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">View</span> questionBox <span style="color: #339933;">=</span> inflater.<span style="color: #006633;">inflate</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">question</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			questionBox.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			TextView title <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">questionTextView</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			title.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			radioGroup <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>RadioGroup<span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">responseRadioGroup</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">String</span> typeFromTable <span style="color: #339933;">=</span> question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;default&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">int</span> responseType <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>typeFromTable<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseType <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">//populate default radio buttons</span>
				Resources res <span style="color: #339933;">=</span> getResources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> defaultAnswers <span style="color: #339933;">=</span> res.<span style="color: #006633;">getStringArray</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">array</span>.<span style="color: #006633;">defaultAnswers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>j <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					RadioButton rb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RadioButton<span style="color: #009900;">&#40;</span>activity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					rb.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>defaultAnswers<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					rb.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					radioGroup.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>rb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					j<span style="color: #339933;">++;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseType <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> j <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;answer&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						RadioButton rb<span style="color: #339933;">;</span>
						rb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RadioButton<span style="color: #009900;">&#40;</span>activity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						rb.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						rb.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;answer&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;answer&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>					
							radioGroup.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>rb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>question.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;answer&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							RadioButton rb<span style="color: #339933;">;</span>
							rb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RadioButton<span style="color: #009900;">&#40;</span>activity<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							rb.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;null&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							rb.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//may not work</span>
							radioGroup.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>rb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #003399;">Button</span> chartsButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">chartsButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			chartsButton.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>question<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Button</span> submitButton <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Button</span><span style="color: #009900;">&#41;</span> questionBox.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">submitButton</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			chartsButton.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span>chartsListener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			submitButton.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span>submitListener<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			TableRow tr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TableRow<span style="color: #009900;">&#41;</span> questionBox<span style="color: #339933;">;</span>
			TableLayout.<span style="color: #006633;">LayoutParams</span> trParams <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TableLayout.<span style="color: #006633;">LayoutParams</span><span style="color: #009900;">&#40;</span>
					TableLayout.<span style="color: #006633;">LayoutParams</span>.<span style="color: #006633;">MATCH_PARENT</span>,
					TableLayout.<span style="color: #006633;">LayoutParams</span>.<span style="color: #006633;">MATCH_PARENT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			trParams.<span style="color: #006633;">setMargins</span><span style="color: #009900;">&#40;</span>leftMargin, topMargin, rightMargin, bottomMargin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//tr.setLayoutParams(trParams);</span>
			tableList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			questionContainer.<span style="color: #006633;">addView</span><span style="color: #009900;">&#40;</span>tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			TagObj tagObj <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TagObj<span style="color: #009900;">&#40;</span>question, radioGroup, tr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			submitButton.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>tagObj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=91</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working AsyncLogin Eclipse Project</title>
		<link>http://davidjkelley.net/?p=85</link>
		<comments>http://davidjkelley.net/?p=85#comments</comments>
		<pubDate>Thu, 26 Apr 2012 20:54:14 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Guides/Tutorials]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=85</guid>
		<description><![CDATA[As per the request of a number of viewers of my previous tutorial, I&#8217;ve uploaded an example AsyncLogin project to help users see the big picture. You need change only two lines to get the registration/login to function with your own database: private static String loginURL = &#34;http://yourWebsite.net/your_Database/&#34;; private static String registerURL = &#34;http://yourWebsite.net/your_Database/&#34;; Change [...]]]></description>
			<content:encoded><![CDATA[<p>As per the request of a number of viewers of my previous tutorial, I&#8217;ve uploaded an example AsyncLogin project to help users see the big picture. You need change only two lines to get the registration/login to function with your own database:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> loginURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://yourWebsite.net/your_Database/&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> registerURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://yourWebsite.net/your_Database/&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Change those lines to represent the URL to your database (or http://localhost/your_Database). </p>
]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=85</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing a login/register system for Android 4.0 &#8211; extending ASyncTask</title>
		<link>http://davidjkelley.net/?p=48</link>
		<comments>http://davidjkelley.net/?p=48#comments</comments>
		<pubDate>Thu, 05 Apr 2012 18:51:03 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[21st Century Polling]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Guides/Tutorials]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=48</guid>
		<description><![CDATA[EDIT~ EDIT~ Due to high demand, I have attached the source project files for this little app! See here: BothAsyncLogins First off, credit where it&#8217;s due. In the past couple of weeks, I tasked myself with completing the register and login systems for my upcoming Android app. After a couple of days of reading up [...]]]></description>
			<content:encoded><![CDATA[<p>EDIT~ EDIT~ Due to high demand, I have attached the source project files for this little app! See here:<br />
<a href='http://davidjkelley.net/wp-content/uploads/2013/02/BothAsyncLogins.zip'>BothAsyncLogins</a></p>
<p>First off, credit where it&#8217;s due. In the past couple of weeks, I tasked myself with completing the register and login systems for my upcoming Android app. After a couple of days of reading up on SQLite and the purely local (to the device) nature of this database structure, I determined that I would need to utilize a MySQL database with PHP scripts hosted from the same location in order to build a fully functioning system. Originally, I followed this tutorial to get the basic understanding: <a href="http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/">http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/</a> by Ravi Tamada. Once I completed that, there was still more to understand, including how to make a login/register system that would be supported by Android 4.0 (by using ASyncTask). For that bit, I followed this tutorial: <a href="http://256design.com/blog/android-login-asynctask/">http://256design.com/blog/android-login-asynctask/</a> by Spencer.</p>
<p>My end result certainly shows the techniques employed by Ravi and Spencer, but the result is unique. So let&#8217;s go over what pieces you need to complete a similar login/register system.</p>
<p>On your localhost SQL dB/web-based SQL dB:</p>
<ul>
<li>Folder /android_api</li>
<li>android_api/index.php</li>
<li>Folder /android_api/include</li>
<li>/include/config.php</li>
<li>/include/DB_Connect.php</li>
<li>/include/DB_Functions.php</li>
</ul>
<p>Android Project Classes:</p>
<ul>
<li>LoginTask.java</li>
<li>RegisterTask.java</li>
<li>MainActivity.java</li>
<li>Separate Package &#8216;library&#8217;</li>
<li>Classes in library: DatabaseHandler.java, JSONParser.java, UserFunctions.java</li>
</ul>
<p>I recognize that this is a fairly large amount of stuff, but it&#8217;s worth it. When you&#8217;ve completed this guide, you will have the ability to create a user account with a unique ID and encrypted password. So, let&#8217;s get started!</p>
<h1><strong>Step 1: Deploying the MySQL database</strong></h1>
<p>Enter PHPMyAdmin, either on your local server (EasyPHP is a great tool for this) or your webserver. Next, create a database named &#8220;android_api&#8221;. Then, under the SQL tab of that table on PHPMyAdmin, enter in this code:</p>
<p><code>create table USERS(</code></p>
<div><code>   </code><code>uid int(</code><code>11</code><code>) primary key auto_increment,</code></div>
<div><code>   </code><code>unique_id varchar(</code><code>23</code><code>) </code><code>not</code> <code>null unique,</code></div>
<div><code>   </code><code>name varchar(</code><code>50</code><code>) </code><code>not</code> <code>null,</code></div>
<div><code>   </code><code>email varchar(</code><code>100</code><code>) </code><code>not</code> <code>null unique,</code></div>
<div><code>   </code><code>encrypted_password varchar(</code><code>80</code><code>) </code><code>not</code> <code>null,</code></div>
<div><code>   </code><code>salt varchar(</code><code>10</code><code>) </code><code>not</code> <code>null,</code></div>
<div><code>   </code><code>created_at datetime,</code></div>
<div><code>   </code><code>updated_at datetime null</code></div>
<div><code>);</code></div>
<div></div>
<p>This bit of SQL code will create the USERS table as we will require it in the later steps of the tutorial. Here&#8217;s what it should look like when you&#8217;ve created the table:</p>
<p><a href="images/logintutorial1.png"><img src="http://www.davidjkelley.net/images/logintutorial1.png" alt="" width="1094" height="345" /></a></p>
<h1><strong>Step 2: Building the PHP script folders</strong></h1>
<p>In the root directory of your localhost/web server, add a new folder, &#8220;android_api&#8221;. Within that folder, add another folder, &#8220;include&#8221;.</p>
<p>We will now construct all of the PHP scripts needed to communicate between the webserver and Android, with PHP being the go-between.</p>
<p>Index.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * File to handle all API requests
 * Accepts GET and POST
 *
 * Each request will be identified by TAG
 * Response will be JSON data
&nbsp;
  /**
 * check for POST request
 */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// get tag</span>
    <span style="color: #000088;">$tag</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// include db handler</span>
    <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'include/DB_Functions.php'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DB_Functions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// response Array</span>
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tag&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tag</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;success&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;error&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// check for tag type</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'login'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Request type is check Login</span>
        <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// check for user</span>
        <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserByEmailAndPassword</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// user found</span>
            <span style="color: #666666; font-style: italic;">// echo json with success = 1</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;unique_id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;updated_at&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;updated_at&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// user not found</span>
            <span style="color: #666666; font-style: italic;">// echo json with error = 0</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error_msg&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Incorrect email or password!&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'register'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Request type is Register new user</span>
        <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// check if user is already existed</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isUserExisted</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// user is already existed - error response</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error_msg&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;User already existed&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// store user</span>
            <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">storeUser</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// user stored successfully</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;unique_id&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;updated_at&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;updated_at&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// user failed to store</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;error_msg&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Error occured in Registartion&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Invalid Request&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Access Denied&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Next up is Config.php, and this is where many folks may trip-up a bit. I suggest you look at the above image displaying the Database&#8217;s table. See how it says localhost -&gt; frehud_android_api? The frehud_ is an added prefix due to my host. You should make sure to check to see if your situation is similar, if so, make sure to specify it wherever it is needed (in the case of my server, user accounts are prefixed xx_account and the database is as well: xx_databaseName:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DB_HOST&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DB_USER&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;yourUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DB_PASSWORD&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;yourPass&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DB_DATABASE&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;yourDbName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>DBConnect.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> DB_Connect <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// constructor</span>
    <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// destructor</span>
    <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// $this-&gt;close();</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Connecting to database</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> connect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'config.php'</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// connecting to mysql</span>
        <span style="color: #000088;">$con</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span>DB_HOST<span style="color: #339933;">,</span> DB_USER<span style="color: #339933;">,</span> DB_PASSWORD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// selecting database</span>
        <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span>DB_DATABASE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// return database handler</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$con</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Closing database connection</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>DB_Functions.php:</p>
<pre lang="&quot;PHP">
<?php

class DB_Functions {

    private $db;

    //put your code here
    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $this->db = new DB_Connect();
        $this->db->connect();
    }

    // destructor
    function __destruct() {

    }

    /**
     * Storing new user
     * returns user details
     */
    public function storeUser($name, $email, $password) {
        $uuid = uniqid('', true);
        $hash = $this->hashSSHA($password);
        $encrypted_password = $hash["encrypted"]; // encrypted password
        $salt = $hash["salt"]; // salt
        $result = mysql_query("INSERT INTO USERS(unique_id, name, email, encrypted_password, salt, created_at) VALUES('$uuid', '$name', '$email', '$encrypted_password', '$salt', NOW())");
        // check for successful store
        if ($result) {
            // get user details
            $uid = mysql_insert_id(); // last inserted id
            $result = mysql_query("SELECT * FROM USERS WHERE uid = $uid");
            // return user details
            return mysql_fetch_array($result);
        } else {
            return false;
        }
    }

    /**
     * Get user by email and password
     */
    public function getUserByEmailAndPassword($email, $password) {
        $result = mysql_query("SELECT * FROM USERS WHERE email = '$email'") or die(mysql_error());
        // check for result
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            $result = mysql_fetch_array($result);
            $salt = $result['salt'];
            $encrypted_password = $result['encrypted_password'];
            $hash = $this->checkhashSSHA($salt, $password);
            // check for password equality
            if ($encrypted_password == $hash) {
                // user authentication details are correct
                return $result;
            }
        } else {
            // user not found
            return false;
        }
    }

    /**
     * Check user is existed or not
     */
    public function isUserExisted($email) {
        $result = mysql_query("SELECT email from USERS WHERE email = '$email'");
        $no_of_rows = mysql_num_rows($result);
        if ($no_of_rows > 0) {
            // user existed
            return true;
        } else {
            // user not existed
            return false;
        }
    }

    /**
     * Encrypting password
     * @param password
     * returns salt and encrypted password
     */
    public function hashSSHA($password) {

        $salt = sha1(rand());
        $salt = substr($salt, 0, 10);
        $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
        $hash = array("salt" => $salt, "encrypted" => $encrypted);
        return $hash;
    }

    /**
     * Decrypting password
     * @param salt, password
     * returns hash string
     */
    public function checkhashSSHA($salt, $password) {

        $hash = base64_encode(sha1($password . $salt, true) . $salt);

        return $hash;
    }

}

?>
</pre>
<h1><strong>Step 3: Android Project/Classes</strong></h1>
<p>We now can begin the work of developing the Android Program. You will need to develop a class and corresponding login file that plays host to a Email EditText and Password EditText. How you design this screen is up to you and what your program should look like. As such, I will focus on the AsyncTask classes first.</p>
<p>Each AsyncTask can use up to three methods. onPreExecute(), doInBackground, onPostExecute(). So how does the AsyncTask get used in Android? Say the user clicks a login button in your main activity/login fragment. An OnClickListener for that button runs the following methods:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">ProgressDialog progressDialog <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ProgressDialog<span style="color: #009900;">&#40;</span>getActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
progressDialog.<span style="color: #006633;">setMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Logging in...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
LoginTask loginTask <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LoginTask<span style="color: #009900;">&#40;</span>getActivity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, progressDialog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
loginTask.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ProgressDialog is created to show the user that the task of connecting to and logging in with the server is underway. When we construct a new loginTask on line 3, we pass it the main activity (in this case we use getActivity() because the class we are working in is actually a fragment: if the class is simply an activity, you can change getActivity() to this), as well as the progressDialog. We then tell the loginTask to execute() &#8211; which begins the AsyncTask by running onPreExecute().</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoginTask <span style="color: #000000; font-weight: bold;">extends</span> AsyncTask <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ProgressDialog progressDialog<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Polling activity<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> JSONParser jsonParser<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> loginURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> registerURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_ERROR_MSG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;error_msg&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_UID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_EMAIL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_CREATED_AT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> LoginTask<span style="color: #009900;">&#40;</span>Polling activity, ProgressDialog progressDialog<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">activity</span> <span style="color: #339933;">=</span> activity<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">progressDialog</span> <span style="color: #339933;">=</span> progressDialog<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see in the constructor above, public LoginTask(&#8230;) {} we have two parameters, Polling activity, ProgressDialog progressDialog that both immediately are employed by linking the class-wide fields, lines 2-3, to their respective parameters. This allows the other methods in AsyncTask to access all the necessary components.</p>
<p>As I mentioned, when we run execute(), the AsyncTask actually runs onPreExecute(). Here is that method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPreExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		progressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Very simple and straightforward: this method places the progressDialog on the screen and doInBackground is automatically launched.</p>
<p>doInBackground() is where the majority of the work is done. Let&#8217;s look at the code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Integer</span> doInBackground<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">arg0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  EditText userName <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">emailEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  EditText passwordEdit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">passEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span> email <span style="color: #339933;">=</span> userName.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span> password <span style="color: #339933;">=</span> passwordEdit.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  UserFunctions userFunction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserFunctions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  JSONObject json <span style="color: #339933;">=</span> userFunction.<span style="color: #006633;">loginUser</span><span style="color: #009900;">&#40;</span>email, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// check for login response</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  <span style="color: #003399;">String</span> res <span style="color: #339933;">=</span> json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_SUCCESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//user successfully logged in</span>
		<span style="color: #666666; font-style: italic;">// Store user details in SQLite Database</span>
		DatabaseHandler db <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatabaseHandler<span style="color: #009900;">&#40;</span>activity.<span style="color: #006633;">getApplicationContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		JSONObject json_user <span style="color: #339933;">=</span> json.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Clear all previous data in database</span>
		userFunction.<span style="color: #006633;">logoutUser</span><span style="color: #009900;">&#40;</span>activity.<span style="color: #006633;">getApplicationContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		db.<span style="color: #006633;">addUser</span><span style="color: #009900;">&#40;</span>json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_NAME<span style="color: #009900;">&#41;</span>, json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_EMAIL<span style="color: #009900;">&#41;</span>,
		  json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_UID<span style="color: #009900;">&#41;</span>, json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_CREATED_AT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//Login Success</span>
		responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	        <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		  responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Error in login</span>
		<span style="color: #009900;">&#125;</span>
	        <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NullPointerException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">return</span> responseCode<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And finally, there is onPostExecute(). This method sends the result of doInBackground back to your login/main class/activity or fragment.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPostExecute<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> responseCode<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		EditText userName <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">emailEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		EditText passwordEdit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">passEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseCode <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//return a successful login</span>
			progressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			activity.<span style="color: #006633;">loginReport</span><span style="color: #009900;">&#40;</span>responseCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			userName.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			passwordEdit.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//shared prefences, store name</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseCode <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//return an error in login</span>
			progressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			activity.<span style="color: #006633;">loginReport</span><span style="color: #009900;">&#40;</span>responseCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And rather than the step by step, let&#8217;s look at RegisterTask.java in full. And remember, it&#8217;s called in the exact same way as LoginTask was up above, with the change being the class/variable name being RegisterTask/registerTask rather than LoginTask/loginTask. Here&#8217;s the full class:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.davekelley.polling</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">library.DatabaseHandler</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">library.JSONParser</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">library.UserFunctions</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.HttpResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.NameValuePair</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.HttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.entity.UrlEncodedFormEntity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.methods.HttpPost</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.impl.client.DefaultHttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.message.BasicNameValuePair</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.actionbarsherlock.R</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.ProgressDialog</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Intent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.AsyncTask</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.FragmentActivity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.util.Log</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.ViewGroup</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Toast</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RegisterTask <span style="color: #000000; font-weight: bold;">extends</span> AsyncTask <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> ProgressDialog progressDialog<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> Polling activity<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> JSONParser jsonParser<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> loginURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> registerURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_SUCCESS <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_ERROR <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;error&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_ERROR_MSG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;error_msg&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_UID <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;uid&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_NAME <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_EMAIL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> KEY_CREATED_AT <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;created_at&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//TextView loginErrorMsg = (EditText)activity.findViewById(R.id.loginErrorMsg);</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> RegisterTask<span style="color: #009900;">&#40;</span>Polling activity, ProgressDialog progressDialog<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">activity</span> <span style="color: #339933;">=</span> activity<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">progressDialog</span> <span style="color: #339933;">=</span> progressDialog<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPreExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		progressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Integer</span> doInBackground<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>... <span style="color: #006633;">arg0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		EditText userName <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">emailEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		EditText passwordEdit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">passEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> email <span style="color: #339933;">=</span> userName.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> password <span style="color: #339933;">=</span> passwordEdit.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Log.<span style="color: #006633;">v</span><span style="color: #009900;">&#40;</span>email, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		UserFunctions userFunction <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> UserFunctions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        JSONObject json <span style="color: #339933;">=</span> userFunction.<span style="color: #006633;">registerUser</span><span style="color: #009900;">&#40;</span> email, password<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// check for login response</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">//registerErrorMsg.setText(&quot;&quot;);</span>
                <span style="color: #003399;">String</span> res <span style="color: #339933;">=</span> json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_SUCCESS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">// user successfully registred</span>
                    <span style="color: #666666; font-style: italic;">// Store user details in SQLite Database</span>
                    DatabaseHandler db <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatabaseHandler<span style="color: #009900;">&#40;</span>activity.<span style="color: #006633;">getApplicationContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    JSONObject json_user <span style="color: #339933;">=</span> json.<span style="color: #006633;">getJSONObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">// Clear all previous data in database</span>
                    userFunction.<span style="color: #006633;">logoutUser</span><span style="color: #009900;">&#40;</span>activity.<span style="color: #006633;">getApplicationContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    db.<span style="color: #006633;">addUser</span><span style="color: #009900;">&#40;</span>json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_NAME<span style="color: #009900;">&#41;</span>,
                    	json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_EMAIL<span style="color: #009900;">&#41;</span>, json.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_UID<span style="color: #009900;">&#41;</span>,
                    	json_user.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span>KEY_CREATED_AT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #666666; font-style: italic;">//successful registration</span>
                    responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">// Error in registration</span>
                	responseCode <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> responseCode<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPostExecute<span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> responseCode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	EditText userName <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">emailEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	EditText passwordEdit <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span>activity.<span style="color: #006633;">findViewById</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">passEditText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> s <span style="color: #339933;">=</span> userName.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseCode <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		progressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		activity.<span style="color: #006633;">registerReport</span><span style="color: #009900;">&#40;</span>responseCode, s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		userName.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		passwordEdit.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>responseCode <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		progressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		activity.<span style="color: #006633;">registerReport</span><span style="color: #009900;">&#40;</span>responseCode, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Don&#8217;t forget that there are a number of other classes utilized in this project, such as JSONParser, DatabaseHandler, and UserFunctions. These classes were created by Ravi Tamada in his excellent tutorial, and you can find the source in the opening paragraph of this post. If all goes well, between following the two above tutorials, and looking at my implementation of AsyncTask, you should have a fully functioning login system to a web-based SQL database right in your very own Android App.</p>
<p>EDIT~ EDIT~ Due to high demand, I have attached the source project files for this little app! See here:<br />
<a href='http://davidjkelley.net/wp-content/uploads/2013/02/BothAsyncLogins.zip'>BothAsyncLogins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=48</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Fully Functioning ViewPager + TabListener for Android 4.0 (ICS) ActionBar Tabs</title>
		<link>http://davidjkelley.net/?p=34</link>
		<comments>http://davidjkelley.net/?p=34#comments</comments>
		<pubDate>Thu, 29 Mar 2012 23:53:38 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[21st Century Polling]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=34</guid>
		<description><![CDATA[I spent about two weeks trying to develop a system of tabs for Android based on the ActionBar as can be seen in ICS&#8217; People, GMail, Play Music, and Play Store. Google has said that this is the future of Android&#8217;s UI paradigm. Without further ado, here&#8217;s my implementation: import java.util.ArrayList; import android.app.ActionBar; import android.app.ActionBar.Tab; [...]]]></description>
			<content:encoded><![CDATA[<p>I spent about two weeks trying to develop a system of tabs for Android based on the ActionBar as can be seen in ICS&#8217; People, GMail, Play Music, and Play Store. Google has said that this is the future of Android&#8217;s UI paradigm. Without further ado, here&#8217;s my implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.ActionBar</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.ActionBar.Tab</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Intent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.util.Log</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.Menu</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.MenuInflater</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.MenuItem</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.MenuItem.OnMenuItemClickListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.Button</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.Fragment</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.FragmentActivity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.FragmentManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.FragmentPagerAdapter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.app.FragmentTransaction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.view.ViewPager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.support.v4.view.ViewPager.OnPageChangeListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Polling <span style="color: #000000; font-weight: bold;">extends</span> FragmentActivity <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> ViewPager mViewPager<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> TabsAdapter mTabsAdapter<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> TAG <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;21st Polling:&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
mViewPager <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ViewPager<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mViewPager.<span style="color: #006633;">setId</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">pager</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
setContentView<span style="color: #009900;">&#40;</span>mViewPager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">final</span> ActionBar bar <span style="color: #339933;">=</span> getActionBar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bar.<span style="color: #006633;">setNavigationMode</span><span style="color: #009900;">&#40;</span>ActionBar.<span style="color: #006633;">NAVIGATION_MODE_TABS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bar.<span style="color: #006633;">setDisplayShowTitleEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
bar.<span style="color: #006633;">setDisplayShowHomeEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
mTabsAdapter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TabsAdapter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, mViewPager<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">login</span><span style="color: #009900;">&#41;</span>,
LoginFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">economics</span><span style="color: #009900;">&#41;</span>,
EconFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">elections</span><span style="color: #009900;">&#41;</span>,
ElectionsFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">politics</span><span style="color: #009900;">&#41;</span>,
PoliticsFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">science</span><span style="color: #009900;">&#41;</span>,
ScienceFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">finance</span><span style="color: #009900;">&#41;</span>,
FinanceFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">religion</span><span style="color: #009900;">&#41;</span>,
ReligionFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">military</span><span style="color: #009900;">&#41;</span>,
MilitaryFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mTabsAdapter.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>bar.<span style="color: #006633;">newTab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">string</span>.<span style="color: #006633;">international</span><span style="color: #009900;">&#41;</span>,
InternationalFragment.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p lang="java">And here&#8217;s the implementation of a subclass that both manages the ViewPager and sets up the TabListener:</p>
<p lang="java">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> TabsAdapter <span style="color: #000000; font-weight: bold;">extends</span> FragmentPagerAdapter
	<span style="color: #000000; font-weight: bold;">implements</span> ActionBar.<span style="color: #006633;">TabListener</span>, ViewPager.<span style="color: #006633;">OnPageChangeListener</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Context</span> mContext<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ActionBar mActionBar<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ViewPager mViewPager<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> ArrayList<span style="color: #339933;">&lt;</span>TabInfo<span style="color: #339933;">&gt;</span> mTabs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>TabInfo<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> TabInfo <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Class<span style="color: #339933;">&lt;?&gt;</span> clss<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Bundle args<span style="color: #339933;">;</span>
&nbsp;
			TabInfo<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> _class, Bundle _args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				clss <span style="color: #339933;">=</span> _class<span style="color: #339933;">;</span>
				args <span style="color: #339933;">=</span> _args<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> TabsAdapter<span style="color: #009900;">&#40;</span>FragmentActivity activity, ViewPager pager<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>activity.<span style="color: #006633;">getSupportFragmentManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mContext <span style="color: #339933;">=</span> activity<span style="color: #339933;">;</span>
			mActionBar <span style="color: #339933;">=</span> activity.<span style="color: #006633;">getActionBar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mViewPager <span style="color: #339933;">=</span> pager<span style="color: #339933;">;</span>
			mViewPager.<span style="color: #006633;">setAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mViewPager.<span style="color: #006633;">setOnPageChangeListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> addTab<span style="color: #009900;">&#40;</span>ActionBar.<span style="color: #006633;">Tab</span> tab, Class<span style="color: #339933;">&lt;?&gt;</span> clss, Bundle args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			TabInfo info <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TabInfo<span style="color: #009900;">&#40;</span>clss, args<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			tab.<span style="color: #006633;">setTag</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			tab.<span style="color: #006633;">setTabListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mTabs.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>info<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mActionBar.<span style="color: #006633;">addTab</span><span style="color: #009900;">&#40;</span>tab<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			notifyDataSetChanged<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> mTabs.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> Fragment getItem<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			TabInfo info <span style="color: #339933;">=</span> mTabs.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> Fragment.<span style="color: #006633;">instantiate</span><span style="color: #009900;">&#40;</span>mContext, info.<span style="color: #006633;">clss</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, info.<span style="color: #006633;">args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onPageScrolled<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #000066; font-weight: bold;">float</span> positionOffset, <span style="color: #000066; font-weight: bold;">int</span> positionOffsetPixels<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onPageSelected<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			mActionBar.<span style="color: #006633;">setSelectedNavigationItem</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onPageScrollStateChanged<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> state<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabSelected<span style="color: #009900;">&#40;</span>Tab tab, FragmentTransaction ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			mViewPager.<span style="color: #006633;">setCurrentItem</span><span style="color: #009900;">&#40;</span>tab.<span style="color: #006633;">getPosition</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			Log.<span style="color: #006633;">v</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;clicked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">Object</span> tag <span style="color: #339933;">=</span> tab.<span style="color: #006633;">getTag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>mTabs.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mTabs.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					mViewPager.<span style="color: #006633;">setCurrentItem</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabUnselected<span style="color: #009900;">&#40;</span>Tab tab, FragmentTransaction ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabReselected<span style="color: #009900;">&#40;</span>Tab tab, FragmentTransaction ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabReselected<span style="color: #009900;">&#40;</span>Tab tab, android.<span style="color: #006633;">app</span>.<span style="color: #006633;">FragmentTransaction</span> ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
		@Override
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabSelected<span style="color: #009900;">&#40;</span>Tab tab, android.<span style="color: #006633;">app</span>.<span style="color: #006633;">FragmentTransaction</span> ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
			<span style="color: #003399;">Object</span> tag <span style="color: #339933;">=</span> tab.<span style="color: #006633;">getTag</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>mTabs.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mTabs.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> tag<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					mViewPager.<span style="color: #006633;">setCurrentItem</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onTabUnselected<span style="color: #009900;">&#40;</span>Tab tab, android.<span style="color: #006633;">app</span>.<span style="color: #006633;">FragmentTransaction</span> ft<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=34</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>SQL-based user account system</title>
		<link>http://davidjkelley.net/?p=26</link>
		<comments>http://davidjkelley.net/?p=26#comments</comments>
		<pubDate>Thu, 29 Mar 2012 23:09:48 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[21st Century Polling]]></category>

		<guid isPermaLink="false">http://davidjkelley.net/?p=26</guid>
		<description><![CDATA[Developing a system to log in and log out of an Android application (and with any future versions of 21st Century Polling, such as Browser or iOS) requires an implementation of an SQL database hosted online. Today, the first bit of success came my way in terms of implementing this system. Unfortunately, the code presented [...]]]></description>
			<content:encoded><![CDATA[<p>Developing a system to log in and log out of an Android application (and with any future versions of 21st Century Polling, such as Browser or iOS) requires an implementation of an SQL database hosted online. Today, the first bit of success came my way in terms of implementing this system. Unfortunately, the code presented below runs on the UI thread. The next step (and my current project) will be converting this code and slimming it down to run as an <strong>AsyncTask</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.ArrayList</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.List</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.NameValuePair</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.message.BasicNameValuePair</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.content.Context</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserFunctions <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> JSONParser jsonParser<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> loginURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> registerURL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://davidjkelley.net/android_api/&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> login_tag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;login&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> register_tag <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;register&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// constructor</span>
    <span style="color: #000000; font-weight: bold;">public</span> UserFunctions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        jsonParser <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONParser<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//login with user provided email/pass </span>
    <span style="color: #000000; font-weight: bold;">public</span> JSONObject loginUser<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> email, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Building Parameters</span>
        <span style="color: #003399;">List</span> params <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tag&quot;</span>, login_tag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span>, email<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span>, password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        JSONObject json <span style="color: #339933;">=</span> jsonParser.<span style="color: #006633;">getJSONFromUrl</span><span style="color: #009900;">&#40;</span>loginURL, params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// return json</span>
        <span style="color: #000000; font-weight: bold;">return</span> json<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//register a new user with name/email/pass</span>
    <span style="color: #000000; font-weight: bold;">public</span> JSONObject registerUser<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, <span style="color: #003399;">String</span> email, <span style="color: #003399;">String</span> password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Building Parameters</span>
        <span style="color: #003399;">List</span> params <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;tag&quot;</span>, register_tag<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>, name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span>, email<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        params.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BasicNameValuePair<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;password&quot;</span>, password<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// getting JSON Object</span>
        JSONObject json <span style="color: #339933;">=</span> jsonParser.<span style="color: #006633;">getJSONFromUrl</span><span style="color: #009900;">&#40;</span>registerURL, params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// return json</span>
        <span style="color: #000000; font-weight: bold;">return</span> json<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//determine if the user is logged in</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> isUserLoggedIn<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        DatabaseHandler db <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatabaseHandler<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> count <span style="color: #339933;">=</span> db.<span style="color: #006633;">getRowCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// user logged in</span>
            <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//logout the user</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> logoutUser<span style="color: #009900;">&#40;</span><span style="color: #003399;">Context</span> context<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        DatabaseHandler db <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DatabaseHandler<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        db.<span style="color: #006633;">resetTables</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://davidjkelley.net/?feed=rss2&#038;p=26</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
