5 Libraries Every Android Developer Should Use

Imran Khan Niazi
Engineering@Tyroo
Published in
3 min readAug 23, 2016

In an era where writing good code and publishing it fast is the key to go ahead, using Library saves a lot time and efforts.

As a lead for our SDK efforts at Tyroo Technologies, i am inclined to share some of our learnings through this blog post. I am going to cover 5 libraries which work as a Catalyst when it comes to Android development, thereby enhancing your productivity. Whats the point of re-inventing the wheel?

Butter Knife

This is small, simple and lightweight, and it makes developer’s life easy. It allows developers to perform injection on arbitrary objects, views and OnClickListeners so they can focus on writing useful code. Consider Android Butter Knife a reduction library. It replaces findViewById with @Bind() and Listener calls with@onClick() making code cleaner and more understandable. Butter Knife enables focus on logic instead of glue code and reduces development time by reducing redundant coding.

//OLD Method
class ExampleActivity extends Activity {
EditText mUserNameEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUserNameEditText = (EditText) view.findViewById(R.id.username);
*****************Butter Knife*********************************//New Methods with Butter knife Injection
class LoginFragment extends Fragment {
@InjectView(R.id.username) EditText username;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);

Event Listener.

@OnClick(R.id.button)
public void ButtonClick() {
//Perform some action
}

The ViewHolder example of a RecyclerView looks like this (In Recycler_View_Adapter.java).

public class View_Holder extends RecyclerView.ViewHolder {    @BindView(R.id.cardView)
CardView cv;
@BindView(R.id.textView)
TextView title;
@BindView(R.id.imageView)
ImageView imageView;
View_Holder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}

ACTIVEANDROID

ActiveAndroid is an ORM for Android. It’s an abstraction over SQLite which allows you to communicate with a database on a device without writing SQL statements. An Object that extends ActiveAndroid Model can be saved to the database like this:

user.save();

which can easily replace a big SQL statement like this:

INSERT INTO Users (Nickname, Name, Address, City, PostalCode, Country) VALUES ('Batman','Bruce W','Palisades 21','Gotham','40000','USA');

An example of retrieving all users:

List<User> users = new Select().from(User.class).execute();

of which SQL counterpart would look like this:

SELECT Nickname, Name, Address, City, PostalCode, Country FROM Users;

ActiveAndroid is a nice way to remove a lot of boilerplate code used for working with databases. There are other open source solutions likeGreenDAO and ORMLite.

Social Login

When you need to give options like Login with Facebook and Login with Google. This is one of the best Libraries to use. This Library provides simple implementation for social login on android.

All you need to do is Register an app on Google Developers console after that, you should ensure which the file google-services.json is inside app module and ,for Facebook Create an app on Facebook Developers and add facebook app id in string.xml

<string name="facebook_app_id">1320760547953881</string>public class MyApplication extends Application {

@Override
public void onCreate() {
super.onCreate();
LoginApplication.startSocialLogin(this);
}
}

Login with google:

loginWithGoogle(new Callback() {
@Override
public void onSuccess(SocialUser socialUser) {
buildProfileDialog(socialUser);
}
@Override
public void onError(Throwable throwable) {
throwable.printStackTrace();
}
});

Login with Facebook:

loginWithFacebook(new Callback() {
@Override
public void onSuccess(SocialUser socialUser) {
buildProfileDialog(socialUser);
}
@Override
public void onError(Throwable throwable) {
throwable.printStackTrace();
}
});

However, if you need to share content then there is another alternative is to avoid creating apps on every single one of these social services and simply employ a share intent. The share intent will let the user share your content using any app they wish.

Universal Image Loader

This is an smart and powerful library that helps in loading, caching and displaying images on Android. This means, using this library you can download remote images and display on ImageView.

// Get singleton instance
ImageLoader imageLoader = ImageLoader.getInstance();
// Load image, decode it to Bitmap and display Bitmap in ImageView
imageLoader.displayImage(imageUri, imageView);

Universal Image Loader Features

  • Asynchronous and multi-threaded image loading. This allows you to download multiple images Asynchronously.
  • Supports various configurations that helps to tune for your requirement. With this you can control memory, cache type, decoder, display image options, etc.
  • Flexibility of changing image caching in memory and/or on device’s file system (or SD card)
  • Scope of listing loading process. Allows various callback methods using which you will get to know the progress/state of your download request.

There are other library also available for image loading like Picasso ,Fresco and Glide but Universal Image Loader looks when it come to me.

Gson

This is a Java library used for serializing and deserializing Java objects from and into JSON. It saves all the time and effort of parsing the Json.

// Serialize 
String userJSON = new Gson().toJson(user);
// Deserialize
User user = new Gson().fromJson(userJSON, User.class);
//Parsing and making POJO
@SerializedName("mobileno")
private String moblieNumber;

These were the 5 that i personally love, however am sure there are others too that you might have used and love. Do share them through comments.

--

--