Android Team Coding Standards

These guidelines should be followed when writing Java and Kotlin code for the Android platform. Patches and additions to any code base will be checked for adherence to these guidelines. If code is in violation, you will be asked to reformat it. For Android Studio you can import the this code style scheme: Vokal.xml (Preferences > Editor > Code Style > Config Icon > Import Scheme...)

There are separate documents for Java Code Standards, Kotlin Code Standards, and Android Resource Formatting Standards

Naming Guidelines

    vokalApi[‘IO’] and not vokalApi[‘Io’]
    vokalApi[‘Api’]

Coding Style

, . ; : { } ( [ = < > ? ! + - * / % ~ ^ | & == != <= >= += -= *= /= %= ^= |= &= << >> || && === !== <<= >>= >>> >>>=
    String someMessage = (conditional) ? "This is the message when some thing is true"
                                       : "This is the message when some thing is false!";
    if (condition) {
        callSomeFunction(args);
    }
    adLayout = (RelativeLayout) findViewById(R.id.ad);
    public void foo() {
        if (condition) {
            ...
        } else if (condition) {
            ...
        }

        while (condition) {
            ...
        }
    }
    int total = x + 2;
    String someString = otherString + anotherString;
    if(variable == 14.76) {
        ...
    }
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONObject;

import com.vokal.myapp.MyClass;

MVVM

    showLoadingDialog()
   onLoginButtonClick()
interface ResProvider {
    fun getString(@StringRes resId: Int): String
}
class MyResProvider(private val app: Application) {
    override fun getString(@StringRes resId: Int): String {
        return app.getString(resId)
    }
}
@Module
class AppModule(private val app: Application) {
    @Provides
    fun getResProvider(): ResProvider {
        return MyResProvider(app)
    }
}
class FeatureViewModel @Inject constructor(resProvider: ResProvider): ViewModel

See our Databinding Coding Standards for code-related info.

MVP

    showLoadingDialog()
   onLoginButtonClick()

Navigation Component

read more...

Implementation Guidelines

Commenting

        i = 0; // Set i to zero.

Additional Information

Architecture Components pitfalls

5 common mistakes when using Architecture Components

Handling Lifecycles with Lifecycle-Aware Components

LiveData Overview