Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building compelling Android apps with Firebase

Building compelling Android apps with Firebase

Adora Nwodo

April 06, 2019
Tweet

More Decks by Adora Nwodo

Other Decks in Programming

Transcript

  1. Hi, I’m Adora! Multidisciplinary software engineer GDG Ajah Co-organizer Women

    Techmakers Ajah Ambassador Blogger, adorahack.com Twitter @theadoranwodo GitHub @adoranwodo 2
  2. Firebase is a web and mobile platform that gives developers

    a variety of tools to build high quality apps 5
  3. Cloud Firestore NoSQL Database ML Kit Machine Learning APIs Cloud

    Functions & Storage 7 Authentication Manage your users efficiently Hosting Simple & Secure hosting Realtime Database NoSQL
  4. 8

  5. Imagine we had an already existing app that has a

    list of motivational quotes on SQLite. If we add a new quote to the app, we have to update the app on the store and our users have to redownload. That’s NOT good enough! Place your screenshot here 10 Motivational Quotes App
  6. 11 It separates the data from the app It also

    works offline Your users don’t have to download a new version of your app when you update data Crash reporting A good idea would be to integrate Firebase. Here’s why
  7. The Final Product 13 Place your screenshot here Quotes are

    now retrieved from the cloud firestore. https://github.com/AdoraNwodo/bookofquotes
  8. Quotes app Step 1: On Android studio, go to Tools

    > Firebase. This will launch a sidebar that looks like this on the right side of your project. 14
  9. Quotes app Step 2: Connect your app to Firebase (by

    clicking on the button provided) Step 3: Add Cloud Firestore to your app (again, by clicking on the button provided). If you’re having issues syncing your project afterwards, go to your app level build.grade and change what looks like the below: implementation 'com.google.firebase:firebase-firestore:18.2.0:15.0.0' to implementation 'com.google.firebase:firebase-firestore:18.2.0' 15
  10. Quotes app Step 4: Go to firebase and add some

    quotes to your project. Also secure your quotes data. Step 5: Create a firebase firestore instance val db = FirebaseFirestore.getInstance() 16
  11. Quotes app Step 6: Create a quotes data class. data

    class Quote(val id: String, val quote: String, val author: String ) Step 7: Create a recyclerview in activity_main.xml <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" /> 17
  12. Quotes app Step 8: Create an xml card layout for

    a single quote. Feel free to get creative. 18
  13. Quotes app Step 9: Create an adapter class for your

    recyclerview. Step 10: Create a method to initialize recyclerview in your Activity. Step 11: Now, we have these things set up, it’s time to retrieve data from firestore with the instance that was initially created. 19
  14. Quotes app db.collection("quotes") .get() .addOnCompleteListener { task -> if (task.isSuccessful)

    { for (document in task.result!!) { quotesList.add( Quote(document.id,document["quote"].toString(), document["author"].toString())) } initRecyclerView(quotesList) //method to initialize recyclerview } else { Log.w("QUOTE_ERROR_TAG", "Error getting documents.", task.exception) } } 20
  15. Moral of the Story The firebase part in the implementation

    was just two. 1. Instantiating Firestore 2. Retrieving data from store Yo! Apart from the fact that it’s a good tool for your apps, it saves you a lot of time . 21
  16. More on Firestore Write to the store Perform simple and

    compound queries Order queries Limit queries 23
  17. 25 Create an (easily trackable) onboarding flow Use personalization efficiently

    for better experiences Get a deep understanding of users across devices Leverage machine learning Add realtime chat with an offline experience
  18. 26 https://firebase.google.com The Definitive Guide to Firebase: Build Android Apps

    on Google's Mobile Platform - Laurence Moroney Mastering Firebase for Android Development: Build Real-time, Scalable, and Cloud-enabled Android Apps with Firebase - Ashok Kumar S Firebase Cookbook: Over 70 recipes to help you create real-time web and mobile applications with Firebase - Houssem Yahiaoui Resources to help you get started with Firebase