Code Style with Android
Introduction
Android is a big platform nowadays and cover almost all segments of society. We can see a variety of products based on the Android platform like Smartphones, Smart Watches and Smart TV, etc. Android is really growing up from cupcake to Android O we gone really intensive open source approach. So we brings Code Style with Android for our readers.
It makes Android very rich in a way of many developers from all over the world contribute their expertise and solve the bugs before the launch of the new version of Android. Many developers contribute in recently development process of Nought and now in Android O.
Exceptions
It can be really painful to ignore exceptions in your code. The code with better exception handling is more stable than without it. You must handle every exception in a principled way,specific cases may want extra code. Don’t catch the generic exception like IO exception, NullPointer exception and ArrayOutOfBound exception instead of these use generic Exception. You can later check what is the specific error by catching the error in that block.
Javadoc Standard Comments
Every file should have Javadoc Standard Comments it can have a copyright declaration, class or interface description. Every method should be well described about what this method can do, what is the its main function. Define fields in Standard places like at the top of the file or immediately before the method declaration.
Set the scope of variable in Code Style with Android
Keeping the scope of variable minimum makes code more readable, maintainable and less error prone. Local variables should declare where they first use.
Follow Variable Naming Conventions
1.Non public and non static fields start with m.
2.Static fields names start with s.
3.Other field start with s.
4.Public static final fields and constant are ALL_CAPS_WITH_UNDERSCORES.
Use standard braces Style like this
class Sample {
void method() {
if (condition) {
// ...
}else {
// ...
}
}
}
Each line of text in code should be at most 100 character long.
Use Standard Java Annotations
@Override
: The @Override annotation must be used whenever a method overrides the declaration or implementation from a super-class. For example, in Android onCreate() method define the parent view of the activity so we override this method with annotation @override..@SuppressWarnings
: The @SuppressWarnings annotation should be used only under circumstances where it is impossible to eliminate a warning. If a warning passes this “impossible to eliminate” test, the @SuppressWarnings annotation must be used, so as to ensure that all warnings reflect actual problems in the code.
Code Style with Android Verdict
The Code should be robust and scale-able, it also consists uniform standard throughout the code structure. It will help the development team to easily understand what is the motive of a particular line of code. Stay tuned for more such articles only on The Smart Innovator.
0 Comments