16 Jan 2016

Android start or stop adb from command line

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.

Open the cmd from Start ⇒ run ⇒ cmd and execute these commands.Before you execute the commands in  CMD make sure that you added the adb tool to your Environment Variables path.

Set path in environment variables :-
"C:\Users\AmarAndroidTech\AppData\Local\Android\Sdk\platform-tools"

Killing adb :- adb kill-server
Starting adb :- adb start-server

Read More !

11 Jan 2016

Naming Conventions in java

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.
2. Avoid overly long names (greater than 15 characters). For example, setTheLengthField should  be shortened tosetLength.
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.
For Ex : -
double tax1;       // sales tax rate (example of poor variable name)
double tax2;       // income tax rate (example of poor variable name)
double salesTaxRate;      //no comments required due to
double incomeTaxRate;     //self-documenting variable names
Variable Naming Conventions :-
Choose meaningful names that describe what the variable is being used for. Avoid generic names like number or temp whose purpose is unclear. Compose variable names using mixed case letters starting with a lower case letter. For example, use salesOrder rather than SalesOrder or sales_order.
Use plural names for arrays. For example, use testScores instead of testScore. Exception: for loop  counter variables are often named simply i, j, or k, and declared local to the for loop whenever possible.
for (int i = 0; i < MAX_TEMPERATURE; i++){
   boilingPoint = boilingPoint + 1;
}

Constant Naming Conventions :- 
Use ALL_UPPER_CASE for your named constants, separating words with the underscore character.  For example, use TAX_RATE rather than taxRate or TAXRATE. 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. 

Method Naming Conventions :-
1.Compose method names using mixed case letters, beginning with a lower case letter and starting each subsequent word with an upper case letter. 

2.Begin method names with a strong action verb (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). 

3.Use the prefixes get and set for getter and setter methods. 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. 

4.If the method returns a boolean value, 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.For example, use  !isOverdrawn instead of isNotOverdrawn.

  

Parameter Naming Conventions :-
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. 

1.Consider using the prefix a or an with parameter names. This helps make the parameter distinguishable from local and instance variables. 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. 
Example:- 
public void deposit(long anAccountNumber, double aDepositAmount)
  ... 
}
public boolean isNumberEven(int aValue)
  ... 
}
Read More !

8 Jan 2016

Android Directory Structure

Within an Android project structure, the most frequently edited folders are:
  • src - Java source files associated with your project. This includes the Activity "controller" files as well as your models and helpers.
  • res - 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.
  • res/layout - XML layout files that describe the views and layouts for each activity and for partial views such as list items.
  • res/values - XML files which store various attribute values. These include strings.xml, dimens.xml, styles.xml, colors.xml, themes.xml, and so on.
  • res/drawable - Here we store the various density-independent graphic assets used in our application.
  • res/mipmap-xhdpi - Series of folders for density specific images to use for various resolutions.
The most frequently edited files are:

  • AndroidManifest.xml - 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.
  • res/layout/activity_main.xml - This file describes the layout of the activity's UI. This means the placement of every view object on one app screen.
  • src/.../MainActivity.java - The Activity "controller" that constructs the activity using the view, and handles all event handling and view logic for one app screen.
Other less edited folders include:
  • gen - Generated Java code files, this library is for Android internal use only.
  • assets - Uncompiled source files associated with your project; Rarely used.
  • bin - Resulting application package files associated with your project once it’s been built.
  • libs - Contains any secondary libraries (jars) you might want to link to your app.

Read More !

1 Jan 2016

Seeing java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

Seeing java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

You have a third-party library reference defined twice. Check your app/build.gradle for duplicate libraries (i.e. commons-io library defined for 1.3 and another one using 2.4).
Read More !