Best practise for Logcat colours in Android Studio!

Android Studio Logcat color scheme Preferences

I know that using solid black colour logcat in Android Studio  is awful !!!

Here is my best practice colour codes that you can use for changing the face of you logcat in Android Studio to make it more useful. go to Android Studio Preferences and search for logcat and save as your own scheme:


All colours are picked from material design colour pattern:

How to solve “Duplicate files copied in APK META-INF/LICENSE.txt”?


Sometimes depends on libraries that you have used in your Android project this annoying error shows up during gradle build using Android Studio: Duplicate files copied in APK META-INF/LICENSE.txt

can be solve this issue and many more by adding this to the Android tag of your build.grade file:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'

How to enable Android retrofit2 network library logging?


As any one who had an experiment with retrofit2 knows, logging is some times required to check what is happening!

Since the retrofit2 required HTTP layer is now completely based on OkHttp, the developers of OkHttp added a logging interceptor in release 2.6.0

add to your build.gradle file:

dependencies {
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'

and this is how to build retrofit:

Retrofit.Builder builder = new Retrofit.Builder()

        //show retrofit logs if is debugging
        if (sIsDebug) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();


        mRetrofit =;

now have fun with logs at logcat…

How to connect your activity to its fragment


Often you will want one Fragment to communicate with its Activity also all Fragment-to-Fragment communication must be done through the associated Activity. Two Fragments should never communicate directly.

Define an Interface
To allow a Fragment to communicate up to its Activity, you can define an interface in the Fragment class and implement it within the Activity.

public class HeadlinesFragment extends ListFragment {
    OnHeadlineSelectedListener mCallback;

    // Container Activity must implement this interface
    public interface OnHeadlineSelectedListener {
        public void onArticleSelected(int position);

    public void onAttach(Activity activity) {
        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception
        try {
            mCallback = (OnHeadlineSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnHeadlineSelectedListener");

Now the fragment can deliver messages to the activity by calling the onArticleSelected() method (or other methods in the interface) using the mCallback instance of the OnHeadlineSelectedListener interface.

Implement the Interface
In order to receive event callbacks from the fragment, the activity that hosts it must implement the interface defined in the fragment class.

public static class MainActivity extends Activity
        implements HeadlinesFragment.OnHeadlineSelectedListener{
    public void onArticleSelected(int position) {
        // The user selected the headline of an article from the HeadlinesFragment
        // Do something here to display that article


full version at:

How to manage your Android Application Settings


Here is my best practice for managing your Android application settings using AppSettings class. by using this class you can save your different variables in shared preferences and also load them to ram when ever needed and use them in memory.

String methods sample:

AppSettings.setValue(this, KEY_NAME, name);
AppSettings.getString(this, KEY_NAME, "");
AppSettings.clearValue(this, KEY_NAME);

Android SQLite create query syntax diagram


All SQLite create queries are based on the following syntax diagram:

sqlite syntax diagram

Here, the keyword create table is used to create a table. This is followed by the table name, the declaration of columns, and their datatype. After preparing our SQL statement, we will execute it using the execSQL() method of the SQLite database.

In case something is wrong with the query statement that we built earlier, we will encounter the exception, android.database.sqlite.SQLiteException. By default, the database is formed in the internal memory space allocated to the application. The folder can be found at


Based on Android SQLite Essentials book:
Android SQLite Essentials

Where can I find the best reference to learn Design Patterns in Java?


Design Patterns in Java Tutorial Design patterns represent the best practices used by experienced object-oriented software developers. Design patterns are solutions to general problems that software developers faced during software development. These solutions were obtained by trial and error by numerous software developers over quite a substantial period of time. This tutorial will take you through step by step approach and examples using Java while learning Design Pattern concepts.

Prerequisites Before you start proceeding with this tutorial, I’m making an assumption that you are already aware about basic java programming concepts. If you are not well aware of these concepts then I will suggest to go through our short tutorial on Java Programming.

Design Patterns Tutorial in PDF