tag:blogger.com,1999:blog-4175566286208821252024-03-12T10:22:32.465+05:30Amar's Android TechThis is a Technology blog about android, android developer tricks and also useful for Students whose learn android programming......Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.comBlogger61125tag:blogger.com,1999:blog-417556628620882125.post-64834572082471638942016-04-13T15:36:00.000+05:302016-04-13T16:37:35.397+05:30git - simple guide<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"><b>1. Setup :- </b></div><span style="font-weight: normal;"> (a) <a href="https://code.google.com/archive/p/git-osx-installer/downloads" target="_blank">git-osx-installer</a><br />
(b) <a href="https://git-for-windows.github.io/" target="_blank">git-for-windows</a><br />
(c) <a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" target="_blank">git-for-linux</a></span><br />
<br />
<b>2. Create a new local repository :-</b><br />
create a new directory, open it and perform a<br />
<span style="color: red;">git init</span> :- to create a new git repository.<br />
<span class="fullpost"><br />
<b>3. Checkout a repository :-</b><br />
Create a working copy of a local repository:<br />
<span style="color: red;">git clone /path/to/repository</span><br />
For a remote server, use:<br />
<span style="color: red;">git clone username@host:/path/to/repository</span><br />
<br />
<b>4. Add & commit :-</b><br />
Add one or more files to staging (index):<br />
<span style="color: red;">git add *</span><br />
Commit changes to head (but not yet to the remote repository):<br />
<span style="color: red;">git commit -m "Commit message"</span><br />
<br />
<b>5. Pushing changes :-</b><br />
Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute :<br />
<span style="color: red;">git status</span> :- List the files you've changed and those you still need to add or commit:<br />
<span style="color: red;">git pull origin master</span> : - if conflict , resolve conflict and again follow <b>step no 4</b>. then push the code.<br />
<span style="color: red;">git push origin master</span> :- push the code to your remote repository.<br />
<br />
<b>6. Branching :-</b><br />
Branches are used to develop features isolated from each other. The master branch is the "default" branch when you create a repository.<br />
Create a new branch and switch to it: <span style="color: red;">git checkout -b b</span><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span><br />
Switch from one branch to another:<span style="color: red;"> git checkout </span><span style="color: red;">b</span><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span><br />
List all the branches in your repository, and also tell you what branch you're currently in:<span style="color: red;"> git branch</span><br />
Delete the feature branch: <span style="color: red;">git branch -d</span> <span style="color: red;">b</span><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span><br />
Push the branch to your remote repository, so others can use it: <span style="color: red;">git push origin </span><span style="color: red;">b</span><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span><br />
Push all branches to your remote repository: <span style="color: red;">git push --all origin</span><br />
Delete a branch on your remote repository: <span style="color: red;">git push origin :<span style="color: red;">b</span><span style="background-color: whitesmoke; color: black; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span></span><br />
<br />
<b>7. Update & merge :-</b><br />
Fetch and merge changes on the remote server to your working directory: <span style="color: red;">git pull</span><br />
To merge a different branch into your active branch:<span style="color: red;"> git merge </span><span style="color: red;">b</span><span style="background-color: whitesmoke; font-size: 14px; line-height: 20px;"><span style="color: red;">ranchname</span></span><br />
if conflict, resolve conflict and again follow step no 4. then push the code in your remote repository.<br />
</span><br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com6Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-10846146987180324962016-04-06T17:26:00.000+05:302016-04-06T17:27:27.263+05:30Get screen dimensions in pixels<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;">If you want the display dimensions in pixels you can use <a href="http://developer.android.com/reference/android/view/Display.html#getSize%28android.graphics.Point%29" target="_blank">getSize</a> :</div><div style="background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;"><div style="line-height: 125%; margin: 0;">Display display = getWindowManager().getDefaultDisplay();</div>Point size = new Point();<br />
display.getSize(size);<br />
int width = size.x;<br />
int height = size.y;</div><span class="fullpost"><br />
<div style="text-align: left;">If you're not in an Activity you can get the default Display via WINDOW_SERVICE:</div><div style="background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;"><div style="line-height: 125%; margin: 0;">WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);</div>Display display = wm.getDefaultDisplay();</div><div style="text-align: left;"><br />
</div><div style="text-align: left;">Before getSize was introduced (in API level 13), you could use the getWidth and getHeight methods that are now deprecated:</div><div style="background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;"><div style="line-height: 125%; margin: 0;">Display display = getWindowManager().getDefaultDisplay();<br />
int width = display.getWidth(); // deprecated<br />
int height = display.getHeight(); // deprecated</div></div><div style="text-align: left;"><br />
</div><div style="text-align: left;">For the use case you're describing however, a margin/padding in the layout seems more appropriate.</div><div style="text-align: left;"><span style="background-color: white; color: #222426; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px; line-height: 19.5px;">Another ways is: <a href="http://developer.android.com/reference/android/util/DisplayMetrics.html" target="_blank">DisplayMetrics</a>.</span></div><div style="text-align: left;"><div style="text-align: left;"><span style="background-color: white; font-size: 15px; line-height: 19.5px;"><span style="color: #222426; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;">A structure describing general information about a display, such as its size, density, and font scaling. To access the DisplayMetrics members, initialize an object like this:</span></span></div></div><div style="background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; text-align: left; width: auto;"><div style="line-height: 125%; margin: 0;"><span style="line-height: 125%;">DisplayMetrics metrics = new DisplayMetrics();</span><br />
<span style="line-height: 125%;">getWindowManager().getDefaultDisplay().getMetrics(metrics);</span><br />
Log.d("ApplicationTagName", "Display width in px is " + metrics.widthPixels);</div></div><div style="text-align: left;"><br />
We can use widthPixels to get information for:</div><div style="text-align: left;">"The absolute width of the display in pixels."</div><div style="text-align: left;">Example:</div><!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0;">Log.d("ApplicationTagName", "Display width in px is " + metrics.widthPixels);
</pre></div></span><br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com2Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-85935134348966632972016-03-28T17:11:00.000+05:302016-03-28T18:11:54.261+05:30How to generate key hash for facebook in android<div dir="ltr" style="text-align: left;" trbidi="on"><b>1. Using OpenSSL and command prompt</b><br />
<ul style="text-align: left;"><li>Download openssl from <a href="https://www.openssl.org/source/" target="_blank">Download</a></li>
<li>Extract it. Create a folder- OpenSSL in C: / and copy all files here</li>
<li>Find “debug.keystore” file path. Most likely it will be inside “C:\Users\\.android” folder. In my system it is under “C:\Program Files\Java\jdk1.7.0_67\bin”</li>
<li>Open command prompt (Run-> cmd->start) and go to java /bin folder (cd “C:\Program Files\Java\jdk1.7.0_67\bin” command will do it for you)</li>
</ul>Now you run the below command.<br />
<span class="fullpost"><br />
<pre data-codota-status="done" data-original-code="C:\\Program Files\\Java\\jdk1.6.0_30\\bin>keytool -exportcert -alias androiddebugkey -keystore "
C:\\Users\\.android\\debug.keystore" | "C:\\OpenSSL\\bin\\openssl" sha1 -binary |"C:\\OpenSSL\bin\\openssl" base64
" data-snippet-id="ext.fc7501d7852483cbc6c07898b432b65d" data-snippet-saved="false" style="background-color: #1d1f21; border: 0px; color: #9197a3; font-family: Consolas, 'Courier New', Courier, monospace; font-size: 14px; line-height: 1.3em; margin-bottom: 1.5em; overflow: auto; padding: 7.5px 10px; vertical-align: baseline; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;">C:\\Program Files\\Java\\jdk1.6.0_30\\bin>keytool -exportcert
-alias androiddebugkey -keystore "C:\\Users\\.android\\debug.keystore" | "C:\\OpenSSL\\bin\\openssl" sha1 -binary |"C:\\OpenSSL\bin\\openssl" base64</pre><pre data-codota-status="done" data-original-code="C:\\Program Files\\Java\\jdk1.6.0_30\\bin>keytool -exportcert -alias androiddebugkey -keystore "C:\\Users\\.android\\debug.keystore" | "C:\\OpenSSL\\bin\\openssl" sha1 -binary |"C:\\OpenSSL\bin\\openssl" base64
" data-snippet-id="ext.fc7501d7852483cbc6c07898b432b65d" data-snippet-saved="false" style="background-color: #1d1f21; border: 0px; margin-bottom: 1.5em; overflow: auto; padding: 7.5px 10px; vertical-align: baseline; word-break: break-all; word-wrap: break-word;"><span style="color: #9197a3; font-family: "consolas" , "courier new" , "courier" , monospace;"><span style="color: #9197a3; font-family: "consolas" , "courier new" , "courier" , monospace; font-size: 14px; line-height: 18.2px; white-space: pre-wrap;">Enter keystore password:android<span style="font-family: "times new roman"; white-space: normal;">
</span></span></span>
</pre><b>2. Using a method call from android code</b><br />
Using below code snippet, you can get the hash code.<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;">@Override</pre>public void <b>onCreate</b>(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
<br />
<b> // Add code to print out the key hash</b><br />
try {<br />
PackageInfo info = getPackageManager().getPackageInfo(<br />
"com.facebook.samples.hellofacebook",<br />
PackageManager.GET_SIGNATURES);<br />
for (Signature signature : info.signatures) {<br />
MessageDigest md = MessageDigest.getInstance("SHA");<br />
md.update(signature.toByteArray());<br />
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));<br />
}<br />
} catch (NameNotFoundException e) {<br />
</div>Check your logcat output for a message.</span></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com6Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-70157841165629981302016-01-16T13:27:00.000+05:302016-01-16T13:27:01.507+05:30Android start or stop adb from command line<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;">
<span style="color: #383838; letter-spacing: 0pt;">Sometimes your android emulator might fails to connect Android Studio DDMS tool and ask for adb to start manually. In that case you can start or stop the adb using the command prompt.</span><br />
<br />
<span style="color: #383838; letter-spacing: 0pt;">Open the cmd from Start ⇒ run ⇒ cmd and execute these commands.</span><span style="color: #383838; letter-spacing: 0pt;">Before you execute the commands in CMD make sure that you added the adb tool to your </span><span style="color: #383838; letter-spacing: 0pt;">Environment Variables path.</span><br />
<span style="color: #383838; letter-spacing: 0pt;"><br /></span>
<span style="color: #383838; letter-spacing: 0pt;">Set path in environment variables :-</span><span style="color: #383838; letter-spacing: 0pt;"><o:p></o:p></span><br />
<div class="p15" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="font-family: inherit;"><span style="color: #383838; letter-spacing: 0pt;">"C:\Users\AmarAndroidTech\AppData\Local\Android\Sdk\platform-tools"</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div>
<div class="p15" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="font-family: inherit;"><br />
</span></div>
<div class="p15" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="font-family: inherit;"><span style="color: #383838; letter-spacing: 0pt;">Killing adb :- </span><span style="color: #383838; font-weight: bold; letter-spacing: 0pt;">adb kill-server</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div>
<div class="p15" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;">
<span style="font-family: inherit;"><span style="color: #383838; letter-spacing: 0pt;">Starting adb :- </span><span style="color: #383838; font-weight: bold; letter-spacing: 0pt;">adb start-server</span></span><br />
<span style="font-family: inherit;"><span style="color: #383838; font-weight: bold; letter-spacing: 0pt;"><br /></span></span></div>
</div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com7Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-61035098489349685582016-01-11T18:19:00.001+05:302016-01-11T19:35:23.776+05:30Naming Conventions in java<div dir="ltr" style="text-align: left;" trbidi="on"><div class="p0" style="margin-bottom: 5pt; margin-left: 36pt; margin-top: 5pt; text-align: justify; text-indent: -18pt;"><div style="line-height: 18.95pt;"></div></div><div class="p0" style="margin-bottom: 5pt; margin-left: 36pt; margin-top: 5pt; text-align: justify; text-indent: -18pt;"><div><div><span style="line-height: 25.2667px;"><span style="font-family: inherit;">1. Use full English descriptions for names. Avoid using abbreviations. For example, use names like firstName,lastName, and middleInitial rather than the shorter versions fName, lName, and mi.</span></span></div><div><span style="line-height: 25.2667px;"><span style="font-family: inherit;">2. Avoid overly long names (greater than 15 characters). For example, setTheLengthField should be shortened tosetLength.</span></span></div><div><span style="line-height: 25.2667px;"><span style="font-family: inherit;">3. Avoid names that are very similar or differ only in case. For example, avoid using the names product, products, and Products in the same program for fear of mixing them up.</span></span></div></div></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">For Ex : -</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">double tax1; // sales tax rate (example of poor variable name)</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">double tax2; // income tax rate (example of poor variable name)</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">double salesTaxRate; //no comments required due to</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">double incomeTaxRate; //self-documenting variable names</span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="color: red; letter-spacing: 0pt;"><b>Variable Naming Conventions :-</b></span></span><br />
<span class="fullpost"><span style="letter-spacing: 0pt;">Choose meaningful names that describe what the variable is being used for. Avoid generic names like number or temp whose purpose is unclear. </span><span style="letter-spacing: 0pt; line-height: 18.95pt;">Compose variable names using mixed case letters starting with a lower case letter. For example, use salesOrder rather than SalesOrder or sales_order.</span></span></div><div class="p0" style="line-height: 18.95pt; margin-bottom: 5pt; margin-top: 5pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">Use plural names for arrays. For example, use testScores instead of testScore. </span><span style="letter-spacing: 0pt; line-height: 18.95pt;">Exception: for loop counter variables are often named simply i, j, or k, and declared local to the for loop whenever possible.</span></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">for (int i = 0; i < MAX_TEMPERATURE; i++){</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;"> boilingPoint = boilingPoint + 1;</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-family: inherit; letter-spacing: 0pt;">}</span></span><br />
<span class="fullpost"><span style="font-family: inherit; letter-spacing: 0pt;"><br />
</span></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: left;"><div style="text-align: justify;"><span class="fullpost"><span style="color: red;"><span style="font-weight: bold; letter-spacing: 0pt;">Constant Naming Conventions</span><span style="font-weight: bold; letter-spacing: 0pt;"> :-</span><span style="letter-spacing: 0pt;"> </span></span></span></div></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: left;"><div style="text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">Use ALL_UPPER_CASE for your named constants, separating words with the underscore character. For example, use TAX_RATE rather than taxRate or TAXRATE. </span><span style="letter-spacing: 0pt; text-align: justify;">Avoid using magic numbers in the code. Magic numbers are actual numbers like 27 that appear in the code that require the reader to figure out what 27 is being used for. Consider using named constants for any number other than 0 and 1. </span></span></div></div></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-weight: bold; letter-spacing: 0pt;"><br />
<span style="color: red;">Method Naming Conventions :-</span></span></span></div><span class="fullpost"><span style="font-family: inherit; font-weight: bold; letter-spacing: 0pt;">1.Compose method names using mixed case letters</span><span style="font-family: inherit; letter-spacing: 0pt;">, beginning with a lower case letter and starting each subsequent word with an upper case letter.</span><span style="font-family: inherit; letter-spacing: 0pt;"> </span><br />
</span><br />
<div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-weight: bold; letter-spacing: 0pt;">2.Begin method names with a strong action verb</span><span style="letter-spacing: 0pt;"> (for example, deposit). If the verb is not descriptive enough by itself, include a noun (for example, addInterest). Add adjectives if necessary to clarify the noun (for example, convertToEuroDollars).</span><span style="letter-spacing: 0pt;"> </span></span></div><span class="fullpost"> </span> <br />
<div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-weight: bold; letter-spacing: 0pt;">3.Use the prefixes get and set for getter and setter methods</span><span style="letter-spacing: 0pt;">. Getter methods merely return the value of a instance variable; setter methods change the value of a instance variable. For example, use the method names getBalance and setBalance to access or change the instance variable balance.</span><span style="letter-spacing: 0pt;"> </span></span></div><span class="fullpost"> </span> <br />
<div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-weight: bold; letter-spacing: 0pt;">4.If the method returns a boolean value</span><span style="letter-spacing: 0pt;">, use is or has as the prefix for the method name. For example, use isOverdrawn or hasCreditLeft for methods that return true or false values. Avoid the use of the word not in the boolean method name, use the ! operator instead.</span><span style="letter-spacing: 0pt;">For example, use !isOverdrawn instead of isNotOverdrawn.</span></span></div><span class="fullpost"> </span> <br />
<div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;"> </span><span style="letter-spacing: 0pt;"> </span></span></div><span class="fullpost"> </span> <br />
<div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="font-weight: bold; letter-spacing: 0pt;"><span style="color: red;">Parameter Naming Conventions :-</span></span></span></div><span class="fullpost"> </span> <div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span class="fullpost"><span style="letter-spacing: 0pt;">With formal parameter names, follow the same naming conventions as with variables, i.e. use mixed case, begin with a lower case letter, and begin each subsequent word with an upper-case letter.</span><span style="letter-spacing: 0pt;"> </span></span></div><span class="fullpost"> <div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-weight: bold; letter-spacing: 0pt;"><br />
</span> <span style="font-weight: bold; letter-spacing: 0pt;">1.Consider using the prefix a or an with parameter names</span><span style="letter-spacing: 0pt;">. This helps make the parameter distinguishable from local and instance variables.</span><span style="letter-spacing: 0pt;"> </span><span style="letter-spacing: 0pt;">Occasionally, with very general purpose methods, the names chosen may be rather generic (for example, aNumber). However, most of the time the parameter names should succinctly describe the type of value being passed into the method.</span><span style="letter-spacing: 0pt;"> </span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">Example:-</span><span style="letter-spacing: 0pt;"> </span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">public void deposit(long anAccountNumber, double aDepositAmount)</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">{ </span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;"> ... </span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">}</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">public boolean isNumberEven(int aValue)</span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;">{ </span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="letter-spacing: 0pt;"> ... </span><span style="letter-spacing: 0pt;"><o:p></o:p></span></div><div class="p0" style="margin-bottom: 0pt; margin-top: 0pt; text-align: justify;"><span style="font-family: inherit; letter-spacing: 0pt;">}</span><br />
<span style="font-size: 12pt; letter-spacing: 0pt;"><o:p></o:p></span></div></span></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com5Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-71542051908692731062016-01-08T15:08:00.001+05:302016-01-08T15:54:30.701+05:30Android Directory Structure<div dir="ltr" style="text-align: left;" trbidi="on"><div style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; text-align: left;"><span style="font-family: inherit;">Within an Android project structure, the most frequently edited folders are:</span></div><ul style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em;"><li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">src</code> - Java source files associated with your project. This includes the Activity "controller" files as well as your models and helpers.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res</code> - Resource files associated with your project. All graphics, strings, layouts, and other resource files are stored in the resource file hierarchy under the res directory.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res/layout</code> - XML layout files that describe the views and layouts for each activity and for partial views such as list items.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res/values</code> - XML files which store various attribute values. These include strings.xml, dimens.xml, styles.xml, colors.xml, themes.xml, and so on.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res/drawable</code> - Here we store the various density-independent graphic assets used in our application.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res/mipmap-xhdpi</code> - Series of folders for density specific images to use for various resolutions.</span></li>
</ul><div><span style="background-color: white; color: #333333; line-height: 23.2727px;">The most frequently edited files are:</span></div><span class="fullpost"><br />
<ul style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em;"><li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">AndroidManifest.xml</code> - This is the Android application definition file. It contains information about the Android application such as minimum Android version, permission to access Android device capabilities such as internet access permission, ability to use phone permission, etc.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">res/layout/activity_main.xml</code> - This file describes the layout of the activity's UI. This means the placement of every view object on one app screen.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">src/.../MainActivity.java</code> - The Activity "controller" that constructs the activity using the view, and handles all event handling and view logic for one app screen.</span></li>
</ul><div><span style="background-color: white; color: #333333; line-height: 23.2727px;">Other less edited folders include:</span></div><ul style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em;"><li style="box-sizing: border-box;"><span class="fullpost" style="font-family: inherit;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">gen</code> - Generated Java code files, this library is for Android internal use only.</span></li>
<li style="box-sizing: border-box;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">assets</code><span style="font-family: inherit; line-height: 23.2727px;"> - Uncompiled source files associated with your project; Rarely used.</span></li>
<li style="box-sizing: border-box;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">bin</code><span style="font-family: inherit; line-height: 23.2727px;"> - Resulting application package files associated with your project once it’s been built.</span></li>
<li style="box-sizing: border-box;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">libs</code><span style="font-family: inherit; line-height: 23.2727px;"> - Contains any secondary libraries (jars) you might want to link to your app.</span></li>
</ul><ul style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em; text-align: left;"><span class="fullpost" style="font-family: inherit;"> </span></ul><div class="separator" style="clear: both; text-align: center;"></span><br />
<span class="fullpost" style="font-family: inherit;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj__IXpVdkq3mGPhpGjdRNWi179_TCaFWl81bcm57gYdV0ZsSw12B577ydCVX_T94JjFphokDvRw110yCot85i3cPIsP-aOCB89AMYQT5oMWXm2xAcn2TCzPtPn_Plf6iJGPPVHJn6ZjhY/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj__IXpVdkq3mGPhpGjdRNWi179_TCaFWl81bcm57gYdV0ZsSw12B577ydCVX_T94JjFphokDvRw110yCot85i3cPIsP-aOCB89AMYQT5oMWXm2xAcn2TCzPtPn_Plf6iJGPPVHJn6ZjhY/s1600/1.png" /></a></span></div></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com3Gurgaon, Haryana 122001, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-15760986858295483742016-01-01T12:31:00.000+05:302016-01-01T12:31:10.445+05:30Seeing java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Seeing java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation</b><br />
<br />
<span style="background-color: white; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 23.2727px;">You have a third-party library reference defined twice. Check your </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">app/build.gradle</code><span style="background-color: white; color: #333333; font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; line-height: 23.2727px;"> for duplicate libraries (i.e. commons-io library defined for 1.3 and another one using 2.4).</span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com3Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-59993694018844752132015-12-21T16:51:00.002+05:302015-12-31T12:29:07.462+05:30OEM USB Drivers<div dir="ltr" style="text-align: left;" trbidi="on">Acer<span class="Apple-tab-span" style="white-space: pre;"> </span> <a href="http://www.acer.com/worldwide/support/mobile.html">http://www.acer.com/worldwide/support/mobile.html</a><br />
alcatel one touch<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.alcatelonetouch.com/global-en/support/">http://www.alcatelonetouch.com/global-en/support/</a><br />
Asus<span class="Apple-tab-span" style="white-space: pre;"> </span> <a href="http://support.asus.com/download/">http://support.asus.com/download/</a><br />
Blackberry <a href="https://swdownloads.blackberry.com/Downloads/entry.do?code=4EE0932F46276313B51570F46266A608">https://swdownloads.blackberry.com/Downloads/entry.do?code=4EE0932F46276313B51570F46266A608</a><br />
Dell<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://support.dell.com/support/downloads/index.aspx?c=us&cs=19&l=en&s=dhs&~ck=anavml">http://support.dell.com/support/downloads/index.aspx?c=us&cs=19&l=en&s=dhs&~ck=anavml</a><br />
Fujitsu<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.fmworld.net/product/phone/sp/android/develop/">http://www.fmworld.net/product/phone/sp/android/develop/</a><br />
Hisense<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://app.hismarttv.com/dss/resourcecontent.do?method=viewResourceDetail&resourceId=16&type=5">http://app.hismarttv.com/dss/resourcecontent.do?method=viewResourceDetail&resourceId=16&type=5</a><br />
HTC<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.htc.com/">http://www.htc.com</a><br />
Click on the support tab to select your products/device. Different regions will have different links.<br />
<span class="fullpost"><br />
Huawei<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://consumer.huawei.com/en/support/index.htm">http://consumer.huawei.com/en/support/index.htm</a><br />
Intel<span class="Apple-tab-span" style="white-space: pre;"> </span> <a href="http://www.intel.com/software/android">http://www.intel.com/software/android</a><br />
Kyocera<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.kyocera-wireless.com/support/phone_drivers.htm">http://www.kyocera-wireless.com/support/phone_drivers.htm</a><br />
Lenovo<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://support.lenovo.com/us/en/GlobalProductSelector">http://support.lenovo.com/us/en/GlobalProductSelector</a><br />
LGE<span class="Apple-tab-span" style="white-space: pre;"> </span> <a href="http://www.lg.com/us/support/software-firmware">http://www.lg.com/us/support/software-firmware</a><br />
Motorola<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="https://motorola-global-portal.custhelp.com/app/answers/detail/a_id/88481/">https://motorola-global-portal.custhelp.com/app/answers/detail/a_id/88481/</a><br />
MTK<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://online.mediatek.com/Public%20Documents/MTK_Android_USB_Driver.zip">http://online.mediatek.com/Public%20Documents/MTK_Android_USB_Driver.zip</a> (ZIP download)<br />
Oppo<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.oppo.com/index.php?q=software/view&sw_id=631">http://www.oppo.com/index.php?q=software/view&sw_id=631</a><br />
Pegatron<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.pegatroncorp.com/download/New_Duke_PC_Driver_0705.zip">http://www.pegatroncorp.com/download/New_Duke_PC_Driver_0705.zip</a> (ZIP download)<br />
Samsung<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.samsung.com/us/support/downloads">http://www.samsung.com/us/support/downloads</a><br />
Sharp<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://k-tai.sharp.co.jp/support/">http://k-tai.sharp.co.jp/support/</a><br />
Sony Mobile Communications<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://developer.sonymobile.com/downloads/drivers/">http://developer.sonymobile.com/downloads/drivers/</a><br />
Toshiba<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://support.toshiba.com/sscontent?docId=4001814">http://support.toshiba.com/sscontent?docId=4001814</a><br />
Xiaomi<span class="Apple-tab-span" style="white-space: pre;"> </span><a href="http://www.xiaomi.com/c/driver/index.html">http://www.xiaomi.com/c/driver/index.html</a><br />
ZTE<span class="Apple-tab-span" style="white-space: pre;"> </span> <a href="http://support.zte.com.cn/support/news/NewsDetail.aspx?newsId=1000442">http://support.zte.com.cn/support/news/NewsDetail.aspx?newsId=1000442</a><br />
</span><br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com1Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-28215995052712096402015-12-18T13:30:00.000+05:302015-12-31T13:30:54.211+05:30Resetting adb in Android studio<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">If you are having issues trying to connect to the emulator or see any type of "Connection refused" errors, you may need to reset the Android Debug Bridge. You can go to </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Tools</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">-></span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Android</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">-></span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Android Device Monitor</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">. Click on the mobile device icon and click on the arrow facing down to find the </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Reset adb</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> option.</span></span><br />
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">Image 1:-</span></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqWtQaa58mlrBdahIxF_6cejEMutji2a1tsUVtM2-XnjLOKoJ-9yJLJVt4EYzbtQqHXpjtigMHswA8zn1LeNV1_KnHArwrJD3Q4R3yQFAPleaFcUJ4v0SGlvygO2yNyZSpQZK9Yy0Y9ck/s1600/adb.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="207" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqWtQaa58mlrBdahIxF_6cejEMutji2a1tsUVtM2-XnjLOKoJ-9yJLJVt4EYzbtQqHXpjtigMHswA8zn1LeNV1_KnHArwrJD3Q4R3yQFAPleaFcUJ4v0SGlvygO2yNyZSpQZK9Yy0Y9ck/s400/adb.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Amar's Android Tech</td></tr>
</tbody></table>
Image 2:-<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPjlwS71pxB4qT5K6nJOdTGOJy0Iiequ361mxJA4hepdHlydHKi8abIq8nbwBLndjMy13cOfZWcpt8PBLL9UFH8HSm7A4ApK84bpaPcvyabp2G0bpYfz4ZmCNYvHfGGLavpTL2Zwovn78/s1600/reset+adb.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPjlwS71pxB4qT5K6nJOdTGOJy0Iiequ361mxJA4hepdHlydHKi8abIq8nbwBLndjMy13cOfZWcpt8PBLL9UFH8HSm7A4ApK84bpaPcvyabp2G0bpYfz4ZmCNYvHfGGLavpTL2Zwovn78/s400/reset+adb.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Amar's Android Tech</td></tr>
</tbody></table>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"><br /></span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com1Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-17995611202636029262015-12-11T12:34:00.000+05:302015-12-31T12:43:54.454+05:30INSTALL_FAILED_OLDER_SDK error message<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #333333; font-family: inherit;"><span style="line-height: 23.2727px;">If your minSdkVersion is higher than the Android version you are using (i.e. using an emulator that supports API 19 and your target version is for API 23), then you may see an error message that appears similar to the following :</span></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtxvPJfa8DqjuRvdrIDYgFpxmJFNEk1Kbkibr5zXO_rvV12VJrVigk6V_4pk2o_CbCDkMhdnj1DO-ezWzUjcmUksV2kmlzSxnQv5EyDL9yj1IDdpUJX-uhfBWOtqiRS9rChgFOmQMiXQw/s1600/Application+Installation+Failed.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="222" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtxvPJfa8DqjuRvdrIDYgFpxmJFNEk1Kbkibr5zXO_rvV12VJrVigk6V_4pk2o_CbCDkMhdnj1DO-ezWzUjcmUksV2kmlzSxnQv5EyDL9yj1IDdpUJX-uhfBWOtqiRS9rChgFOmQMiXQw/s400/Application+Installation+Failed.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Application Installation Failed</td></tr>
</tbody></table>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 23.2727px;">You will need to either lower the </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">minSdkVersion</code><span style="background-color: white; color: #333333; line-height: 23.2727px;"> or upgrade to an Android emulator or device that supports the minimum SDK version required.</span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com3Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-52565743424326042742015-12-05T13:10:00.000+05:302015-12-31T13:22:19.440+05:30Seeing java.lang.OutOfMemoryError : GC overhead limit when compiling<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 23.2727px;">You are most likely exhausting the heap size especially during compilation. Try to add inside this setting in your </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; margin: 0px; padding: 0.2em 0px;">app/build.gradle</code><span style="background-color: white; color: #333333; line-height: 23.2727px;">:</span></span><br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;">android {
.
.
.
dexOptions {
javaMaxHeapSize "4g"
}
}
</pre></div><br />
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 23.2727px;">You can also reduce the build time too by setting </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; margin: 0px; padding: 0.2em 0px;">incremental</code><span style="background-color: white; color: #333333; line-height: 23.2727px;"> to be true:</span></span><br />
<br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;">android {
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
</pre></div><br />
<div style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px;"><span style="font-family: inherit;">Still not working? Try to increase the heap size of Android Studio.</span></div><ol style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px; margin-top: 0px; padding: 0px 0px 0px 2em;"><li style="box-sizing: border-box;"><span style="font-family: inherit;">Quit Android Studio.</span></li>
<li style="box-sizing: border-box;"><div style="box-sizing: border-box; margin-bottom: 16px; margin-top: 16px;"><span style="font-family: inherit;">Create or edit a <a href="http://tools.android.com/tech-docs/configuration" style="background-color: transparent; box-sizing: border-box; color: #4078c0; cursor: pointer; text-decoration: none;"><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; margin: 0px; padding: 0.2em 0px;">studio.vmoptions</code> file</a>.</span></div><ul style="box-sizing: border-box; margin-bottom: 0px; margin-top: 0px; padding: 0px 0px 0px 2em;"><li style="box-sizing: border-box;"><span style="font-family: inherit;">On Mac, this file should be in <code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; margin: 0px; padding: 0.2em 0px;">~/Library/Preferences/AndroidStudio/studio.vmoptions</code>.</span></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;">On Windows, it should be in <code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; margin: 0px; padding: 0.2em 0px;">%USERPROFILE%\.AndroidStudio\studio[64].exe.vmoptions</code>.</span></li>
</ul><div style="box-sizing: border-box; margin-bottom: 16px; margin-top: 16px;"><span style="font-family: inherit;">Increase the maximum memory to 2 Gb and max heap size of 1 Gb.</span></div><pre style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-stretch: normal; line-height: 1.45; margin-bottom: 16px; overflow: auto; padding: 16px; word-wrap: normal;"><code style="background: transparent; border-radius: 3px; border: 0px; box-sizing: border-box; display: inline; line-height: inherit; margin: 0px; max-width: initial; overflow: initial; padding: 0px; word-break: normal; word-wrap: normal;"><span style="font-family: inherit;"> -Xmx2048m
-XX:MaxPermSize=1024m`
</span></code></pre></li>
<li style="box-sizing: border-box;"><span style="font-family: inherit;">Start Android Studio.</span></li>
</ol></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-70230860196600598012015-11-28T12:51:00.000+05:302015-12-31T12:55:26.293+05:30Getting "com.android.dex.DexException: Multiple dex files define"<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-family: inherit;">One of the issues in the new Gradle build system is that you can often get "Multiple dex files define" issues.</span><br />
<span style="font-family: inherit;"><br />
</span> <span style="font-family: inherit;">If a library is included twice as a dependency you will encounter this issue. Review the libs folder for JARS and the gradle file at app/build.gradle and see if you can identify the library dependency that has been loaded into your application twice.</span><br />
<span style="font-family: inherit;"><br />
</span> <span style="font-family: inherit;">If one dependency library already includes an identical set of libraries, then you may have to make changes to your Gradle configurations to avoid this conflict. This problem usually happens when there are multiple third-party libraries integrated into your code base.</span><br />
<span style="font-family: inherit;"><br />
</span> <span style="font-family: inherit;">Another error if you attempt to include a library that is a subset of another library. For instance, suppose we included the Google play-services library but thought we also needed to include it with the play-services-map library.:</span><br />
<span style="font-family: inherit; line-height: 125%;"><br />
</span><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">dependencies {
compile 'com.google.android.gms:play-services:6.5.+'
compile 'com.google.android.gms:play-services-maps:6.5.+'
}</pre></div><br />
<span style="font-family: inherit; line-height: 125%;">It turns out that having both is redundant and will cause errors. It is necessary in this case to remove one or the other, depending on your need to use other Google API libraries.</span></div></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-87548304927676272232015-11-16T12:57:00.000+05:302015-12-31T13:00:43.352+05:30Getting "tooling.GradleConnectionException" errors<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">If you see </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">org.gradle.tooling.GradleConnectionException</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> errors, you may need to install a newer version of JDK (there have been reports of 1.7.0_71 having this issue). First try to restart the adb server first.</span></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs1ej6FAoKv9Lgd0U46cf0RPXchMn7CI4suGnYUmTW7dmet-mXU72xJiCVn35QQw8OD08PrkY2G1WMLbzuTXEMkKROaDCQmBTOkmRQpIiMVW1TK1zwrcK4VoLQ_h2ps1rIasvisTZ4qCI/s1600/tooling.GradleConnectionException.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="24" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs1ej6FAoKv9Lgd0U46cf0RPXchMn7CI4suGnYUmTW7dmet-mXU72xJiCVn35QQw8OD08PrkY2G1WMLbzuTXEMkKROaDCQmBTOkmRQpIiMVW1TK1zwrcK4VoLQ_h2ps1rIasvisTZ4qCI/s640/tooling.GradleConnectionException.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Amar's Android Tech</td></tr>
</tbody></table>
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"><br /></span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-13508105243854028972015-11-07T12:46:00.000+05:302015-12-31T12:48:22.999+05:30Getting "failed to find Build Tools revision x.x.x"<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #333333; font-family: inherit; line-height: 23.2727px;">If you're opening another Android Studio project and the project fails to compile, you may see "failed to find Build Tools revision x.x.x" at the bottom of the screen. </span><br />
<span style="background-color: white; color: #333333; font-family: inherit; line-height: 23.2727px;">Since this package is constantly being changed, it should be no surprise that other people who have installed Android Studio may have different versions. You can either click the link below to install this specific Build Tools version, or you can modify the build.gradle file to match the version you currently have installed.</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge7zX9C1d5jfIJXAGHxaltY6FsDDf79k8P9UhI6Tzo327gJLDiPY45gAzJpWkoBdeHQMRjMG7Sa2yPNakNEBG50elzDjCUKU15u5n6sUI8CwTonZuXFm0ypqtZxV23e24gcqlbIOnP4pw/s1600/Build+Tools.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="35" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge7zX9C1d5jfIJXAGHxaltY6FsDDf79k8P9UhI6Tzo327gJLDiPY45gAzJpWkoBdeHQMRjMG7Sa2yPNakNEBG50elzDjCUKU15u5n6sUI8CwTonZuXFm0ypqtZxV23e24gcqlbIOnP4pw/s400/Build+Tools.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Amar's Android Tech</td></tr>
</tbody></table>
<span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"><span style="font-family: inherit;"><br /></span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com1Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-13433928226316177492015-10-26T11:39:00.000+05:302015-12-31T12:44:17.152+05:30Seeing Unsupported major.minor version 52.0 on some plugins<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; line-height: 23.2727px;">Some Android Studio plugins do not support Java 1.6 anymore, so it's best to confirm what version you are using. Inside Android Studio, click on </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">About Android Studio</code><span style="background-color: white; color: #333333; line-height: 23.2727px;">. You should see the JRE version listed as 1.x.x below :</span></span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuY46Uc4dQNIv5uRJxV3iTfTtlvat14Hh2C3k9YL4eaa-YEENbhtTYfeZMVU-TXk6ZFXvunu61GOGU5byzUoJ8ZXCMUSrHOCFOlefxhJ_oge2CGS-K3RVJDvIYFN_1Acbe0kHmtF25o1s/s1600/JRE+version.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuY46Uc4dQNIv5uRJxV3iTfTtlvat14Hh2C3k9YL4eaa-YEENbhtTYfeZMVU-TXk6ZFXvunu61GOGU5byzUoJ8ZXCMUSrHOCFOlefxhJ_oge2CGS-K3RVJDvIYFN_1Acbe0kHmtF25o1s/s400/JRE+version.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Amar's Android Tech</td></tr>
</tbody></table>
<div style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px;">
<span style="font-family: inherit;">If you have multiple Java versions installed, you should make sure that v1.6 is not being used.</span></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px;">
<span style="font-family: inherit;">On OS X machines, you can remove the JDK from being noticed. You can move it the temporary directory in case other issues are created by this change.</span></div>
<div class="top-box hide" style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px;">
<div class="alert-info" style="box-sizing: border-box;">
</div>
</div>
<div class="highlight highlight-source-shell" data-codota-status="done" data-csrftoken="rHLn4qNV-7cHmqEyb-j6wps1pkiVENhIri1o" data-original-code="sudo mv /System/Library/Java/JavaVirtualMachines/1.6.0.jdk /tmp" data-snippet-id="ext.ab741b6d7e8b345d06db354f7668bbc1" data-snippet-saved="false" style="background-color: white; box-sizing: border-box; color: #333333; line-height: 23.2727px; margin-bottom: 16px;">
<pre style="background-color: #f7f7f7; border-radius: 3px; box-sizing: border-box; font-stretch: normal; line-height: 1.45; overflow: auto; padding: 16px; word-break: normal; word-wrap: normal;"><span style="font-family: inherit;">sudo mv /System/Library/Java/JavaVirtualMachines/1.6.0.jdk /tmp</span></pre>
</div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-74776991691565428942015-10-17T12:01:00.000+05:302015-12-31T13:03:29.662+05:30Unable to delete emulator getting "AVD is currently running in the Emulator"<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;"><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;">Open the </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">Tools => Android => AVD Manager</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> and select virtual device that you want to delete. Click on the down arrow at the end and select the </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">[Show on Disk]</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> option which will open the emulator directory. Inside the </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">[Your Device].avd</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> folder, locate any </span><code style="background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px; box-sizing: border-box; color: #333333; font-size: 13.6px; margin: 0px; padding: 0.2em 0px;">*.lock</code><span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"> files and delete them. You can now delete the emulator.</span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-27805032145141458202015-10-10T12:05:00.000+05:302015-12-31T13:08:54.412+05:30Android Studio is Crashing or Freezing Up<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #333333; font-family: inherit; font-size: 16px; line-height: 23.2727px;">If Android Studio starts freezing up or crashing even after rebooting the IDE or your computer, your Studio has likely become corrupted. The best way to resolve this is to clear all the caches by removing all the following folders:</span><br />
<span style="background-color: white; color: #333333; font-family: inherit; font-size: 16px; line-height: 23.2727px;"><br /></span>
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">~/Library/Application Support/AndroidStudio
~/Library/Caches/AndroidStudio
~/Library/Logs/AndroidStudio
~/Library/Preferences/AndroidStudio
</pre>
</div>
<span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"><span style="font-family: inherit;"><br /></span></span>
<span style="background-color: white; color: #333333; font-size: 16px; line-height: 23.2727px;"><span style="font-family: inherit;">and then uninstall Android Studio and re-install the latest stable version. This should allow you to boot Android Studio again without errors.</span></span></div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.4594965 77.026638300000059 28.4594965 77.026638300000059tag:blogger.com,1999:blog-417556628620882125.post-78179924175997187952015-10-05T13:30:00.000+05:302015-10-05T13:30:01.643+05:30Add application shortcut to the home screen<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;">In this post, I will be discussing about how to create shortcut for Android applications programmatically.</span></span><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;"><b>What is Android Shortcut?</b></span></span><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;">Android allows you to create app shortcuts, but you can also create special shortcuts that link directly to screens within an app. For example, shortcuts could link to the Navigation screen in Maps or any screen in the Settings app.</span></span><br />
<b> <span style="color: #333333;"><span style="background-color: white; line-height: 26px;">To Create Shortcut</span></span></b><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;">It is very simple to create shortcut programmatically, all you need to do is broadcast the intent with necessary information.</span></span><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;"><b>Below code snippet will create the shortcut.</b></span></span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #888888;">//create shortcuts of app</span>
Intent HomeScreenShortCut<span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Intent<span style="color: #333333;">(</span>getApplicationContext<span style="color: #333333;">(),</span>
MainActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">class</span><span style="color: #333333;">);</span>
HomeScreenShortCut<span style="color: #333333;">.</span><span style="color: #0000cc;">setAction</span><span style="color: #333333;">(</span>Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">ACTION_MAIN</span><span style="color: #333333;">);</span>
HomeScreenShortCut<span style="color: #333333;">.</span><span style="color: #0000cc;">putExtra</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"duplicate"</span><span style="color: #333333;">,</span> <span style="color: #008800; font-weight: bold;">false</span><span style="color: #333333;">);</span>
<span style="color: #888888;">//shortcutIntent is added with addIntent</span>
Intent addIntent <span style="color: #333333;">=</span> <span style="color: #008800; font-weight: bold;">new</span> Intent<span style="color: #333333;">();</span>
addIntent<span style="color: #333333;">.</span><span style="color: #0000cc;">putExtra</span><span style="color: #333333;">(</span>Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">EXTRA_SHORTCUT_INTENT</span><span style="color: #333333;">,</span> HomeScreenShortCut<span style="color: #333333;">);</span>
addIntent<span style="color: #333333;">.</span><span style="color: #0000cc;">putExtra</span><span style="color: #333333;">(</span>Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">EXTRA_SHORTCUT_NAME</span><span style="color: #333333;">,</span> <span style="background-color: #fff0f0;">"Matrialtest"</span><span style="color: #333333;">);</span>
addIntent<span style="color: #333333;">.</span><span style="color: #0000cc;">putExtra</span><span style="color: #333333;">(</span>Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">EXTRA_SHORTCUT_ICON_RESOURCE</span><span style="color: #333333;">,</span>
Intent<span style="color: #333333;">.</span><span style="color: #0000cc;">ShortcutIconResource</span><span style="color: #333333;">.</span><span style="color: #0000cc;">fromContext</span><span style="color: #333333;">(</span>getApplicationContext<span style="color: #333333;">(),</span>
R<span style="color: #333333;">.</span><span style="color: #0000cc;">drawable</span><span style="color: #333333;">.</span><span style="color: #0000cc;">ic_launcher</span><span style="color: #333333;">));</span>
addIntent<span style="color: #333333;">.</span><span style="color: #0000cc;">setAction</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"com.android.launcher.action.INSTALL_SHORTCUT"</span><span style="color: #333333;">);</span>
getApplicationContext<span style="color: #333333;">().</span><span style="color: #0000cc;">sendBroadcast</span><span style="color: #333333;">(</span>addIntent<span style="color: #333333;">);</span></pre>
<pre style="line-height: 125%; margin: 0;"><span style="color: #333333;">
</span></pre>
</div>
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;"><b>Add add this permission to your manifest</b></span></span><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;"><!-- HTML generated using hilite.me --></span></span><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #333333;"><span style="background-color: white; line-height: 26px;"><span style="color: #007700;"><uses-permission</span> <span style="color: #0000cc;">android:name=</span><span style="background-color: #fff0f0;">"com.android.launcher.permission.INSTALL_SHORTCUT"</span> <span style="color: #007700;">/></span></span></span></pre>
</div>
<span style="background-color: white; color: #333333; line-height: 26px;">That’s all. It’s time to test our code.</span><br />
<span style="color: #333333;"><span style="background-color: white; line-height: 26px;">Run the application using emulator or device by right clicking on the project >> Run as >> Android application >> Choose emulator or device.</span></span></div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-84782880410335297272015-09-28T12:32:00.000+05:302015-09-28T12:32:00.080+05:30Error:failed to find Build Tools revision 23.0.0 rc2<div dir="ltr" style="text-align: left;" trbidi="on">
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">Going crazy with <span style="color: #008800; font-weight: bold;">this</span> error from about a couple of hours<span style="color: #333333;">.</span>
The error <span style="color: #997700; font-weight: bold;">is:</span>
failed to find Build Tools revision <span style="color: #6600ee; font-weight: bold;">23.0</span><span style="color: #333333;">.</span><span style="color: #0000dd; font-weight: bold;">0</span> rc1
But I think to have all update
</pre>
</div>
<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">I could fix it by changing it to
android <span style="color: #333333;">{</span>
compileSdkVersion <span style="color: #0000dd; font-weight: bold;">22</span>
buildToolsVersion <span style="background-color: #fff0f0;">"22.0.0"</span>
<span style="color: #333333;">}</span>
in build<span style="color: #333333;">.</span><span style="color: #0000cc;">gradle</span> file
</pre>
</div>
<br />
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
Open the SDK Manager and find the version of the Android SDK Build-tools which is installed and that you want to use. Then go to Gradle Scripts > build.gradle (Module: app). Set the buildToolsVersion to your version.</div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
There is an easier solution. "<b>Right click on the project > Open Module Settings. Choose the Complie Sdk Version and Build Tools Version you want to use".</b></div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-16155292218634169612015-09-25T12:03:00.001+05:302015-09-25T12:03:35.973+05:30Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry has been closed.<div dir="ltr" style="text-align: left;" trbidi="on"><div style="background-color: white; border: 0px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 22px; line-height: 1.3; margin: 0px 0px 0.5em; padding: 0px; text-align: left;"><a class="question-hyperlink" href="https://www.blogger.com/null" style="border: 0px; color: #222222; cursor: pointer; font-size: 24px; font-weight: normal; line-height: 1.35; margin: 0px 0px 0.5em; padding: 0px; text-decoration: none;">Gradle project refresh failed. Android Studio</a></div><span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 10.5px;">I get this error when trying to run my App on Android Studio.</span><br />
<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 10.5px;"></span> <br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;">Gradle <span style="background-color: #ffaaaa; color: red;">'</span>MyApp<span style="background-color: #ffaaaa; color: red;">'</span> refresh failed<span style="color: #333333;">.</span>
<span style="color: #997700; font-weight: bold;">Error:</span>Cannot locate factory <span style="color: #008800; font-weight: bold;">for</span> objects of type DefaultGradleConnector<span style="color: #333333;">,</span> as ConnectorServiceRegistry has been closed<span style="color: #333333;">.</span>
</pre></div><br />
<span style="background-color: white; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px;"><b>Just Restarting Android Studio usually fixes this error for me.</b></span><br />
<br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-77644907408998097932015-09-23T18:05:00.000+05:302015-09-24T10:43:12.224+05:30Pan Card Validation in Android EditText<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="header" style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
<div class="summary" id="ctl00_description" itemprop="headline" style="border: 0px; color: grey; margin: 0px; padding: 30px 0px 0px;">
Sample code for PAN card number validation.</div>
<span class="date" content="http://codeproject.cachefly.net/script/Articles/Images/tip100x80.png" id="ctl00_thumbnailUrl" itemprop="image" style="border: 0px; margin: 0px; padding: 0px;"></span></div>
<div class="text" id="contentdiv" itemprop="articleBody" style="background-color: white; border: 0px; margin: 0px; padding: 10px 0px 0px;">
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
PAN card number is a unique national number issued in India for tax related purposes.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<br /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<span style="background-color: #eeeeee; color: #222222; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; line-height: 16.9px; white-space: pre-wrap;">PAN structure is as follows: AAAAA9999A: First five characters are letters, next 4 numerals, last character letter.</span></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
<span style="background-color: #eeeeee; color: #222222; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; line-height: 16.9px; white-space: pre-wrap;"><br />
</span></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px;">
To validate PAN card, call this line of code :-</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">mEdtPanNumber<span style="color: #333333;">.</span><span style="color: #0000cc;">addTextChangedListener</span><span style="color: #333333;">(</span><span style="color: #008800; font-weight: bold;">new</span> TextWatcher<span style="color: #333333;">()</span> <span style="color: #333333;">{</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">onTextChanged</span><span style="color: #333333;">(</span>CharSequence s<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> start<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> before<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> count<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// TODO Auto-generated method stub</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">afterTextChanged</span><span style="color: #333333;">(</span>Editable editable<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>editable<span style="color: #333333;">.</span><span style="color: #0000cc;">length</span><span style="color: #333333;">()</span> <span style="color: #333333;">==</span> <span style="color: #0000dd; font-weight: bold;">10</span><span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
String s <span style="color: #333333;">=</span> editable<span style="color: #333333;">.</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">();</span> <span style="color: #888888;">// get your editext value here</span>
Pattern pattern <span style="color: #333333;">=</span> Pattern<span style="color: #333333;">.</span><span style="color: #0000cc;">compile</span><span style="color: #333333;">(</span><span style="background-color: #fff0f0;">"[a-z]{5}[0-9]{4}[a-z]{1}"</span><span style="color: #333333;">);</span>
Matcher matcher <span style="color: #333333;">=</span> pattern<span style="color: #333333;">.</span><span style="color: #0000cc;">matcher</span><span style="color: #333333;">(</span>s<span style="color: #333333;">);</span>
<span style="color: #888888;">// Check if pattern matches</span>
<span style="color: #008800; font-weight: bold;">if</span> <span style="color: #333333;">(</span>matcher<span style="color: #333333;">.</span><span style="color: #0000cc;">matches</span><span style="color: #333333;">())</span> <span style="color: #333333;">{</span>
panNumber <span style="color: #333333;">=</span> editable<span style="color: #333333;">.</span><span style="color: #0000cc;">toString</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span> <span style="color: #008800; font-weight: bold;">else</span> <span style="color: #333333;">{</span>
Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">makeText</span><span style="color: #333333;">(</span>DetailsActivity<span style="color: #333333;">.</span><span style="color: #0000cc;">this</span><span style="color: #333333;">,</span> getString<span style="color: #333333;">(</span>R<span style="color: #333333;">.</span><span style="color: #0000cc;">string</span><span style="color: #333333;">.</span><span style="color: #0000cc;">plz_enter_your_correct_pan_num</span><span style="color: #333333;">),</span> Toast<span style="color: #333333;">.</span><span style="color: #0000cc;">LENGTH_LONG</span><span style="color: #333333;">).</span><span style="color: #0000cc;">show</span><span style="color: #333333;">();</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">}</span>
<span style="color: #555555; font-weight: bold;">@Override</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">beforeTextChanged</span><span style="color: #333333;">(</span>CharSequence s<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> start<span style="color: #333333;">,</span> <span style="color: #333399; font-weight: bold;">int</span> count<span style="color: #333333;">,</span>
<span style="color: #333399; font-weight: bold;">int</span> after<span style="color: #333333;">)</span> <span style="color: #333333;">{</span>
<span style="color: #888888;">// TODO Auto-generated method stub</span>
<span style="color: #333333;">}</span>
<span style="color: #333333;">});</span>
</pre>
</div>
<br /></div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com1Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-21733912050197114282015-07-22T11:00:00.000+05:302015-07-22T11:00:00.089+05:30How to get sha1 key in android studio<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
get SHA1 in Android Studio</div>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
If you have android studio then it is very very simple. Just create a MapActivity using android studio and after creating it go into google_maps_api.xml and in there there will be a link given in comments. If you paste it in your browser, it will ask a few details to be filled and after that your api will be generated. No need of using keytool and all.</div>
<ol style="background-color: white; border: 0px; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin: 0px 0px 1em 30px; padding: 0px;">
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;">Click on your package and choose New -> Google -> Google Maps Activity</li>
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;">Android Studio redirect you to google_maps_api.xml</li>
</ol>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
And you will see all you need to get google_maps_key</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6EfGhWu5JmlIEOvc_54k27Kai-ueskTrIxqP8ZQXk0u5B7SgXPCMauvfXPCll8E58g6puGFY-QbJpTmNvha81UX6rIG1b9x-PAY2oZt6WzV6_U0cBZD1YbrW7fUD8_Itr8wESFsc5tI0/s1600/wpLLt.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="355" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6EfGhWu5JmlIEOvc_54k27Kai-ueskTrIxqP8ZQXk0u5B7SgXPCMauvfXPCll8E58g6puGFY-QbJpTmNvha81UX6rIG1b9x-PAY2oZt6WzV6_U0cBZD1YbrW7fUD8_Itr8wESFsc5tI0/s640/wpLLt.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">SHA1 Key in Android Studio</td></tr>
</tbody></table>
<div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;">
<br /></div>
</div>
Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-36427356409165303972015-07-18T17:28:00.000+05:302015-07-18T17:28:00.934+05:30Difference between padding and margin<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">Padding is used to offset the content of a view by specifying pixels. For example a left padding of 2 wil push views content 2 pixels right side of the left edge. Use android:padding</span></div><div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">android:paddingBottom,</span><span style="font-family: Arial, Helvetica, sans-serif;">android:paddingLeft,</span><span style="font-family: Arial, Helvetica, sans-serif;">android:paddingRight,</span><span style="font-family: Arial, Helvetica, sans-serif;">android:paddingTop to set padding on various sides of the content of that view.</span></div><div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">Margin specifies the extra space left on all four sides of a view. Margin space is generally outside the view's bounds. To leave space on left side use android:margin_left, to leave space on other sides use android:layout_marginRight, android:layout_marginTop, android:layout_marginBottom etc..</span></div><div style="text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">In Simple words .. if you want to take your widget like TextView, EditText far away from other. You should use margin from top,right,left,bottom.</span></div><span class="fullpost"><br />
<div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">By increasing padding it will increase the inner spacing not making the widget far apart from others..</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbIOJi4n7Sto8RU6malvOsTgQMVEA9FMBROuwWnzvZp2O_TesiilYoIFbPBWKiCZYHtFN-Vhyphenhyphennp9HjKJhONav15VHyn2TIGAazkJudYG3suNsUuG4JTk3Eaqp8Eczl7OmZFD0VtAkmb20/s1600/pXcPb.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: black; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbIOJi4n7Sto8RU6malvOsTgQMVEA9FMBROuwWnzvZp2O_TesiilYoIFbPBWKiCZYHtFN-Vhyphenhyphennp9HjKJhONav15VHyn2TIGAazkJudYG3suNsUuG4JTk3Eaqp8Eczl7OmZFD0VtAkmb20/s400/pXcPb.jpg" width="400" /></span></a></div><div class="separator" style="clear: both; text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><b><span style="font-family: Arial, Helvetica, sans-serif;">"Padding is inside of a View.</span><span style="font-family: Arial, Helvetica, sans-serif;">Margin is outside of a View."</span></b></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">This difference may be relevant to background or size properties.</span></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><strong style="border: 0px; margin: 0px; padding: 0px;"><span style="font-family: Arial, Helvetica, sans-serif;">Margin:-</span></strong></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">Margins make up the vertical and horizontal areas between elements. If elements have no margins around them, they will bump right up against each other. In other words, he space outside of, or between, elements is what comprises the margin areas.</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimndz9Y1zgnoXJDSwJkrOBQKY1pNNu7wyNogTm26ppEJcVDvuSe5y5kp5VO9ZHZlvdghv3PSEXZZlkcbFlIPTELWsNBnBKqhXdJTvrzlhBS5WPxk7LuR0TpnQ1KRgsZfoO9Bfg9_BTUto/s1600/margin.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="color: black; font-family: Arial, Helvetica, sans-serif;"><img border="0" height="234" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimndz9Y1zgnoXJDSwJkrOBQKY1pNNu7wyNogTm26ppEJcVDvuSe5y5kp5VO9ZHZlvdghv3PSEXZZlkcbFlIPTELWsNBnBKqhXdJTvrzlhBS5WPxk7LuR0TpnQ1KRgsZfoO9Bfg9_BTUto/s400/margin.jpg" width="400" /></span></a></div><div class="separator" style="clear: both; text-align: center;"><span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><strong style="border: 0px; margin: 0px; padding: 0px;"><span style="font-family: Arial, Helvetica, sans-serif;">Padding:-</span></strong></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;">The padding of an element is the horizontal and vertical space that’s set around the content area of the targeted element. So padding is on the inside of a box, not the outside.</span></div><div class="separator" style="clear: both; text-align: center;"><span style="color: black; font-family: Arial, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTpBNNF-TjGGCvIin9dneLXL3EOnyJpinne49QFL8-GdpfPqZlByu5u_JdZWn8YfXPmqeQ7-fCUj21n0By6dA14yifQVVRX442N15aHthQIkwyINaE1pz4wpFOrkiksLStGBl89pnD9u0/s1600/padding.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="178" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTpBNNF-TjGGCvIin9dneLXL3EOnyJpinne49QFL8-GdpfPqZlByu5u_JdZWn8YfXPmqeQ7-fCUj21n0By6dA14yifQVVRX442N15aHthQIkwyINaE1pz4wpFOrkiksLStGBl89pnD9u0/s400/padding.jpg" width="400" /></a></span></div><div style="background-color: white; border: 0px; clear: both; line-height: 19.5px; margin-bottom: 1em; padding: 0px; text-align: left;"><span style="font-family: Arial, Helvetica, sans-serif;"><br />
</span></div><div style="background-color: white; border: 0px; clear: both; color: #222222; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 15px; line-height: 19.5px; margin-bottom: 1em; padding: 0px;"><br />
</div></span><br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-91733340322694531922015-07-15T16:05:00.000+05:302015-07-15T16:05:00.378+05:30What is the use of asynctask in android ?<div dir="ltr" style="text-align: left;" trbidi="on"><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;">AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.</span><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-color: #f9f9f9; line-height: 19px;"><br />
</span> <span style="background-color: #f9f9f9; line-height: 19px;">An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">Params</code><span style="background-color: #f9f9f9; line-height: 19px;">, </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">Progress</code><span style="background-color: #f9f9f9; line-height: 19px;"> and </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">Result.</code><span style="background-color: #f9f9f9; line-height: 19px;">and </span></span><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;">4 steps, called </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">onPreExecute</code><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;">, </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">doInBackground</code><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;">, </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">onProgressUpdate</code><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;"> and </span><code style="background-color: #f9f9f9; font-stretch: normal; line-height: 14px;">onPostExecute</code><span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 19px;">.</span><br />
<span class="fullpost"><br />
<span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 30px;"><br />
</span> <span style="background-color: #f9f9f9; font-family: Arial, Helvetica, sans-serif; line-height: 30px;">AsyncTask's generic types</span><br />
</span><br />
<hr style="background: rgb(204, 204, 204); border: 0px; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; height: 1px; line-height: 19px; margin: 3px 0px 12px;" /><div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">The three types used by an asynchronous task are the following:</span></span></div><ol style="background-color: #f9f9f9; line-height: 19px; margin: 0px 0px 15px 18px; padding: 0px;"><li style="margin: 0px 0px 5px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;">Params</code>, the type of the parameters sent to the task upon execution.</span></span></li>
<span class="fullpost">
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;">Progress</code>, the type of the progress units published during the background computation.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;">Result</code>, the type of the result of the background computation.</span></li>
</span></ol><div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">Not all types are always used by an asynchronous task. To mark a type as unused, simply use the type <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/java/lang/Void.html" style="text-decoration: none;">Void</a></code>:</span></span></div><pre class="prettyprint" data-codota-status="done" data-csrftoken="6cbJGGo4-l1M12eKBEfz0iKf7RbBXTYn9Mmc" data-original-code=" private class MyTask extends AsyncTask<Void, Void, Void> { ... }
" data-snippet-id="ext.6916bc3cf38da6814b88555dc86b639c" data-snippet-saved="false" style="background: rgb(247, 247, 247) !important; border: 1px solid rgb(221, 221, 221) !important; color: #006600; font-size: 13px; font-stretch: normal; line-height: 1.5; margin-bottom: 1em !important; overflow: auto !important; padding: 1em !important;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;"><span class="pln"> </span><span class="kwd">private</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">MyTask</span><span class="pln"> </span><span class="kwd">extends</span><span class="pln"> </span><span class="typ">AsyncTask</span><span class="pun"><</span><span class="typ">Void</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Void</span><span class="pun">,</span><span class="pln"> </span><span class="typ">Void</span><span class="pun">></span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="pun">...</span><span class="pln"> </span><span class="pun">}</span></span></span></pre><h2 style="background-color: #f9f9f9; font-weight: 300; line-height: 30px; margin: 32px 0px 0px; padding: 0px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">The 4 steps</span></span></h2><hr style="background: rgb(204, 204, 204); border: 0px; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; height: 1px; line-height: 19px; margin: 3px 0px 12px;" /><div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">When an asynchronous task is executed, the task goes through 4 steps:</span></span></div><ol style="background-color: #f9f9f9; line-height: 19px; margin: 0px 0px 15px 18px; padding: 0px;"><li style="margin: 0px 0px 5px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPreExecute()" style="text-decoration: none;">onPreExecute()</a></code>, invoked on the UI thread before the task is executed. This step is normally used to setup the task, for instance by showing a progress bar in the user interface.</span></span></li>
<span class="fullpost">
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#doInBackground(Params...)" style="text-decoration: none;">doInBackground(Params...)</a></code>, invoked on the background thread immediately after <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPreExecute()" style="text-decoration: none;">onPreExecute()</a></code> finishes executing. This step is used to perform background computation that can take a long time. The parameters of the asynchronous task are passed to this step. The result of the computation must be returned by this step and will be passed back to the last step. This step can also use <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress(Progress...)" style="text-decoration: none;">publishProgress(Progress...)</a></code> to publish one or more units of progress. These values are published on the UI thread, in the <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onProgressUpdate(Progress...)" style="text-decoration: none;">onProgressUpdate(Progress...)</a></code> step.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onProgressUpdate(Progress...)" style="text-decoration: none;">onProgressUpdate(Progress...)</a></code>, invoked on the UI thread after a call to <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#publishProgress(Progress...)" style="text-decoration: none;">publishProgress(Progress...)</a></code>. The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. For instance, it can be used to animate a progress bar or show logs in a text field.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)" style="text-decoration: none;">onPostExecute(Result)</a></code>, invoked on the UI thread after the background computation finishes. The result of the background computation is passed to this step as a parameter.</span></li>
</span></ol><h2 style="background-color: #f9f9f9; font-weight: 300; line-height: 30px; margin: 32px 0px 0px; padding: 0px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Cancelling a task</span></span></h2><hr style="background: rgb(204, 204, 204); border: 0px; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; height: 1px; line-height: 19px; margin: 3px 0px 12px;" /><div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">A task can be cancelled at any time by invoking <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#cancel(boolean)" style="text-decoration: none;">cancel(boolean)</a></code>. Invoking this method will cause subsequent calls to <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#isCancelled()" style="text-decoration: none;">isCancelled()</a></code> to return true. After invoking this method, <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onCancelled(Result)" style="text-decoration: none;">onCancelled(Object)</a></code>, instead of <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)" style="text-decoration: none;">onPostExecute(Object)</a></code> will be invoked after <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#doInBackground(Params...)" style="text-decoration: none;">doInBackground(Object[])</a></code> returns. To ensure that a task is cancelled as quickly as possible, you should always check the return value of <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#isCancelled()" style="text-decoration: none;">isCancelled()</a></code> periodically from <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#doInBackground(Params...)" style="text-decoration: none;">doInBackground(Object[])</a></code>, if possible (inside a loop for instance.)</span></span></div><h2 style="background-color: #f9f9f9; font-weight: 300; line-height: 30px; margin: 32px 0px 0px; padding: 0px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif; font-size: small;">Threading rules</span></span></h2><hr style="background: rgb(204, 204, 204); border: 0px; color: #222222; font-family: Roboto, sans-serif; font-size: 14px; height: 1px; line-height: 19px; margin: 3px 0px 12px;" /><div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">There are a few threading rules that must be followed for this class to work properly:</span></span></div><ul style="background-color: #f9f9f9; line-height: 19px; margin: 0px 0px 15px 18px; padding: 0px;"><li style="margin: 0px 0px 5px;"><span class="fullpost"><span style="font-family: Arial, Helvetica, sans-serif;">The AsyncTask class must be loaded on the UI thread. This is done automatically as of <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/Build.VERSION_CODES.html#JELLY_BEAN" style="text-decoration: none;">JELLY_BEAN</a></code>.</span></span></li>
<span class="fullpost">
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;">The task instance must be created on the UI thread.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;"><code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#execute(Params...)" style="text-decoration: none;">execute(Params...)</a></code> must be invoked on the UI thread.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;">Do not call <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPreExecute()" style="text-decoration: none;">onPreExecute()</a></code>, <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)" style="text-decoration: none;">onPostExecute(Result)</a></code>, <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#doInBackground(Params...)" style="text-decoration: none;">doInBackground(Params...)</a></code>, <code style="font-stretch: normal; line-height: 14px;"><a href="http://developer.android.com/reference/android/os/AsyncTask.html#onProgressUpdate(Progress...)" style="text-decoration: none;">onProgressUpdate(Progress...)</a></code> manually.</span></li>
<li style="margin: 0px 0px 5px;"><span style="font-family: Arial, Helvetica, sans-serif;">The task can be executed only once (an exception will be thrown if a second execution is attempted.)</span></li>
</span></ul></div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054tag:blogger.com,1999:blog-417556628620882125.post-85158567935498964132015-07-11T15:59:00.000+05:302015-07-11T15:59:00.791+05:30Difference between Service, Async Task & Thread?<div dir="ltr" style="text-align: left;" trbidi="on"><div><ul style="background-color: white; border: 0px; line-height: 19.5px; margin: 0px 0px 1em 30px; padding: 0px; text-align: left;"><li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;"><div style="border: 0px; clear: both; margin-bottom: 1em; padding: 0px;"><span style="font-family: Arial, Helvetica, sans-serif;">Service is like an Activity but has no interface. Probably if you want to fetch the weather for example you won't create a blank activity for it, for this you will use a Service.</span></div></li>
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;"><div style="border: 0px; clear: both; margin-bottom: 1em; padding: 0px;"><span style="font-family: Arial, Helvetica, sans-serif;">A Thread is a Thread, probably you already know it from other part. You need to know that you cannot update UI from a Thread. You need to use a Handler for this, but read further.</span></div></li>
<li style="border: 0px; margin: 0px 0px 0.5em; padding: 0px; word-wrap: break-word;"><div style="border: 0px; clear: both; margin-bottom: 1em; padding: 0px;"><span style="font-family: Arial, Helvetica, sans-serif;">An AsyncTask is an intelligent Thread that is advised to be used. Intelligent as it can help with it's methods, and there are two methods that run on UI thread, which is good to update UI components.</span></div></li>
</ul><div><span style="color: #222222; font-family: Helvetica Neue, Helvetica, Arial, sans-serif;"><span style="font-size: 15px; line-height: 19.5px;"><br />
</span></span></div></div><span class="fullpost"><br />
<div><table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="background: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #666666; font-family: Roboto, sans-serif; font-size: 14px; line-height: 28px; margin: 0px; padding: 0px;"><tbody style="box-sizing: border-box; margin: 0px; padding: 0px;">
<tr style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><br style="box-sizing: border-box; margin: 0px; padding: 0px;" /></div></td><td style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Service</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Thread</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">IntentService</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; height: 26.85pt; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">AsyncTask</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td></tr>
<tr style="box-sizing: border-box; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">When to use ?<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Task with no UI, but shouldn't be too long. Use threads within service for long tasks.<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- Long task in general.<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- For tasks in parallel use Multiple threads (traditional mechanisms)<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- Long task</span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">usually</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">with no communication to main thread.<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-size: 13.3333320617676px; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">(Update)</span>- If communication is required, can use main thread handler or broadcast intents<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- When callbacks are needed (Intent triggered tasks). <o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- Small task having to communicate with main thread.<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- For tasks in parallel use multiple instances OR Executor</span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td></tr>
<tr style="box-sizing: border-box; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Trigger</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Call to method<br style="box-sizing: border-box; margin: 0px; padding: 0px;" />onStartService()<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Thread start() method<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Intent<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Call to method execute()<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td></tr>
<tr style="box-sizing: border-box; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Triggered From (thread)</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Any thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Any Thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Main Thread (Intent is received on main thread and then worker thread is spawed)<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Main Thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td></tr>
<tr style="box-sizing: border-box; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Runs On (thread)</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Main Thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Its own thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Separate worker thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Worker thread. However, Main thread methods may be invoked in between to publish progress.<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td></tr>
<tr style="box-sizing: border-box; margin: 0px; padding: 0px;"><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Limitations /</span></span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><span style="background: 0px 0px; border: 0px; box-sizing: border-box; font-size: 13.3333320617676px; font-weight: 700; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Drawbacks</span><o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">May block main thread<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- Manual thread management<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- Code may become difficult to read<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- Cannot run tasks in parallel.<br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- Multiple intents are queued on the same worker thread.<o:p style="box-sizing: border-box; margin: 0px; padding: 0px;"></o:p></span></div></td><td style="box-sizing: border-box; margin: 0px; padding: 0.75pt;"><div class="MsoNormal" style="background: 0px 0px; border: 0px; box-sizing: border-box; line-height: 13.5pt; margin: 0px 0px 0cm; outline: 0px; padding: 0px; vertical-align: baseline;"><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">- one instance can only be executed once (hence cannot run in a loop)</span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"> </span><span style="background: 0px 0px; border: 0px; box-sizing: border-box; color: #222222; font-family: Arial, sans-serif; font-size: 10pt; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;"><br style="box-sizing: border-box; margin: 0px; padding: 0px;" /><br style="box-sizing: border-box; margin: 0px; padding: 0px;" />- Must be created and executed from the Main thread</span></div></td></tr>
</tbody></table></div><div><br />
</div></span><br />
</div>Amardeepvijayhttp://www.blogger.com/profile/04491525898437072270noreply@blogger.com0Gurgaon, Haryana, India28.4594965 77.02663830000005928.236067 76.703914800000064 28.682926000000002 77.349361800000054