The effortless in-app notification library for your Android app

Shasindran Poonudurai
MindOrks
Published in
3 min readMar 17, 2018

As an Android developer, you need the skills at your fingertips to develop easy or complex UI components for your app. My most recent work demanded to develop a custom notification banner for in-app notifications.

The easiest implementation would be using the popular Toast or SnackBar UI components provided by Android SDK.

Snackbar
Toast

However, customisation is an issue with those libraries. As a solution, you can find many custom libraries from a bunch of awesome people who open source their hard work.

Below are some of the libraries that I find impressive and easy to use:

  1. Custom Toast

2. Custom Snackbar

These libraries are great to use. However, they didn’t meet the design requirement that needed to complete my work. Furthermore, I had the challenge to show the notification regardless of the Activity/Screen as a listener object listening to incoming in-app notification events.

I ended up creating my own notification library to allow easy customisation as well as using default Notification UI components for future use.

Top Notification Banner

To show the notification regardless of current visible screen, I decided to use a base activity class and let the other activity classes inherit it.

In onCreate method of your base activity class, create a root view object that needed to show the notification banner and implement Notification listener as shown below:

Create a notification banner easily with a line of code as implemented in showNotification() method:

Now let’s create a presenter class for MainActivity class and invoke presenter methods in MainActivity:

Make sure your MainActivity class inherits BaseActivity class and invoke callNotificationAPI()wherever required.

That’s it. We have implemented in app notification with few lines of code.

The library allows customizing your own notification layout. You can implement your own layout, custom animation, auto dismiss and custom click listeners as shown below:

The result:

Happy coding! Any contribution or discussion to improve the library is welcomed.

Updates:
NotificationBanner is being used in production apps that serves more than 100k users
https://medium.com/kaodim-engineering/android-how-to-implement-a-custom-progressview-for-your-brand-3cd112ea2c78

Before you go…

If you liked this article, please hit 👏 clap. Do you know you can clap more than once? Do you know you can clap up to 50 times?

--

--