Must use Android Libraries

Below are my favorites and must use library for every Android Project.
1) ButterKnife
2) Retrofit
3) Glide
4) Parceler

ButterKnife

Field and method binding for Android views which uses annotation processing. ButterKnife makes your code cleaner and under-stable.

class ExampleActivity extends Activity {
  @BindView(R.id.user) EditText username;
  @BindView(R.id.pass) EditText password;

  @BindString(R.string.login_error) String loginErrorMessage;

  @OnClick(R.id.submit) void submit() {
    // TODO call server...
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);
    ButterKnife.bind(this);
    // TODO Use fields...
  }
}

Retrofit

Retrofit turns your HTTP API into a Java interface.

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

The Retrofit class generates an implementation of the GitHubService interface.

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();
GitHubService service = retrofit.create(GitHubService.class);
Call<List<Repo>> repos = service.listRepos("octocat");

Each Call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote webserver.

Glide

Glide is a fast and efficient open source media management and image loading framework.

Glide.with(this).load(url).into(imageView);

Glide includes a large number of features. Some of the more notable features are

  • Animated GIF decoding
  • Local video stills
  • Thumbnail suppor
  • Lifecycle integration
  • Transcoding
  • Animations

Advantages:

  • Automatic job cancellation in lists where views are re-used.
  • Background image loading.
  • Memory and disk caching and easier to configure
  • Bitmap and resource pooling

Parceler

Parceler is a easiest way to serialize Java Objects between Contexts.

@Parcel
public class Example {
    String name;
    int age;

    public Example() {}

    public Example(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public String getName() { return name; }

    public int getAge() { return age; }
}

Add wrapped object to bundle

Bundle bundle = new Bundle();
bundle.putParcelable("example", Parcels.wrap(new Example("Andy", 42)));

And dereferenced in the onCreate() method:

Example example = Parcels.unwrap(getIntent().getParcelableExtra("example"));

Leave a Reply

Your email address will not be published. Required fields are marked *