Build an Android app logging system using Firebase, Part 2

Azzeddine CHENINE
4 min readJul 16, 2017

--

Hello again guys and gals ! last time we finished building both the splash and the authentication fragments, and now it’s time to finished our launcher activity, So let’s ROCK 👊!

As mentioned in the previous part the user can continue using the app with his Facebook account credentials (email, username and profile picture).

Providing this features requires following these two steps:

1-Create your app at Facebook developers website:

On the top right of the screen select My Apps then create a new app .

2-Enable Facebook authentication with the Firebase :

From Facebook developers app dashboard copy the APP ID and the APP secret to the Facebook sign in method section at the Firebase console .

Sign in method page at the Firebase console

Then to complete setup, copy the OAuth redirect URI to the Client OAuth Settings in the Facebook app dashboard:

Don’t get tired your almost done 👊 ! we need to create Android Facebook Key Hash. So, open the Android studio terminal and run this command :

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

The default password is: android.

Getting the Android Facebook key hash

Copy the generated key, go to you dashboard > settings > basics and past it as shown below :

Finally go the strings resource file and get it done !

Creating the Launcher activity

this activity is used as a shared one between the two fragments that we had already created.Furthermore, implementing the AnimationListener interface and holding all the authentication logic we are insuring that our code matches the Android development Fragment communication guidelines.

First, create the layout file which is dead simple !

Now, it’s different I’m not going the full activity code, instead we are creating it together step by step

1. Setup the activity java class and the Android manifest :

After the splash screen animation is finished it’s time to use some Firebase features in our app starting with FirebaseAuth .

2. Setup the Firebase utils class :

3- Implement the AnimationListener interface in the launcher activity:

Like we had mentioned before our main activity needs to implement the AnimationListener interface.As a result we need to override the following methods:

The only methods which we are interested in is “onAnimationEnd”, where we will be on face of two case

  1. the user is not authenticated: we start the authentication fragment. Moreover, starting from Android Lollipop we can use some cool transition between fragments like animating the shared elements between scenes( the app logo) and overriding the default enter transition of the screen content.
  2. the user is already authenticated: here things are easy, we go directly to the chat activity.

To reduce code duplication we are using a simple method called ‘startChatActivity’ to start the chat activity and removing the launcher activity from the back stack.

4- Writing the handler methods code :

The launcher activity handles all the logic of the user authentication :

1- the sign in :

2- the registration :

3- Facebook authentication:

We need to set up one more method we are done “showProgress”, it displays a progress bar while the authentication network process.

Hi five 👋 ! you’re done with the launcher activity. Next time we will be writing some Javascript ES6 code with the new Firebase cloud function.So stay tuned !

PS :

  • If you encounter any code bugs or didn’t understand something, you can mention them at the GitHub issues section.
  • You can report language error on the comments 🤔 .

--

--

Azzeddine CHENINE

AI Research Engineer @instadeepai │ ML @GoogleDevExpert