Architecture/Coding
Standard
For Android Projects
Variable Naming convention
1. Non-public, non-static field names start with m.
a. private int mPrivate;
2. Static field names start with s.
a. private static MyClass sSingleton;
3. Other fields start with a lower case letter.
a. int mPackagePrivate;
Xml / source naming
1. In XML - sepration by underscore
a. Resources file names are written in lowercase_underscore.
b. user_name
2. In Source
- userName or mUserName
Drawable Files
Icon
ic_
ic_star.png
Menu
menu
menu_submenu
Notification
notification_bg
Layout file name
Activity
UserProfileActivity
activity_user_profile.xml
Fragment
SignUpFragment
fragment_sign_up
Import
Bed
import foo.*;
Good
import foo.Bar;
Class/Package naming
Class
Start with capital latter and camel case
For classes that extend an Android component, the name of the class should end with the
name of the component;
ShippereApplication
SignInActivity, SignInFragment, ImageUploaderService, ChangePasswordDialog.
Package name
Limit Veriable scope
Private
Protective
Public
Don’t ignore exception
GOOD - Coding
void setServerPort(String value) {
try {
serverPort = Integer.parseInt(value);
} catch (NumberFormatException e) { }
}
BED - Coding
try {
someComplicatedSecurityFunction(); // may throw
SecurityException
// phew, made it all the way
} catch (Exception e) { // I'll just catch all
exceptions
handleError(); // with one generic handler!
}
Indentation
4 Space for Block
if (x == 1) {
x++;
}
8 for line wrap
Instrument i =
someLongExpression(that, wouldNotFit, on, one, line);
Constants
SharedPreference
PREF_
Arguments
ARGUMENT_
Extra
EXTRA_
static final String PREF_EMAIL = "PREF_EMAIL";
XMl Style Rule
GOOD
<TextView
android:id="@+id/text_view_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
BAD
<TextView
android:id="@+id/text_view_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TextView>
String.xml
error_
msg_
menu_
action_
title_
nav_
Attribute Order
Id
Style
Height / width
Other layout attributes, sorted alphabetically
Thank you!!
Contact Me
Ravishankar Ahirwar - Android Developer
Email : ravishankar.ahirwar@gmail.com

Android Coding Standered