Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is firebase and how to use it in Android? [closed]

I want to create an android app, where I, as an author, upload my college notes and anyone can download it. I read that firebase can help me with this. Can anyone please explain what is firebase and how to use it with my reference? Thank you!

like image 690
Nirup Iyer Avatar asked Nov 15 '15 14:11

Nirup Iyer


People also ask

What is Firebase in Android used for?

Google Firebase is a Google-backed application development software that enables developers to develop iOS, Android and Web apps. Firebase provides tools for tracking analytics, reporting and fixing app crashes, creating marketing and product experiment.

Does Firebase work offline?

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.

What is the main use of Firebase?

Firebase helps you develop high-quality apps, grow your user base, and earn more money. Each feature works independently, and they work even better together.

What is Firebase in Android example?

Firebase is a backend platform for building Web, Android and IOS applications. It offers real time database, different APIs, multiple authentication types and hosting platform.


1 Answers

Update: Since Google I/O 2016 there have been some major updates to Firebase. Below is information related to the legacy service.

Firebase team member here.

tl;dr - Read this Quickstart, watch this video. Use FirebaseUI.

Firebase is a platform for mobile and web apps.

There's three main services to Firebase:

  • Realtime database
  • Authentication
  • Static Hosting

Setup

For writing an Android app you need to download the Android SDK. If you have Android Studio 1.4 you can setup Firebase by going to File > Project Structure > Cloud. Then click the Firebase checkbox.

Saving and Retrieving data

Every Firebase app has a name, and that is used to in a URL to access your database. Data is stored in Firebase in JSON. Each piece has a URL mapped to its location. To get or save data to that location you create a Firebase reference.

// Create a reference to the Firebase database Firebase ref = new Firebase("https:<MY-FIREBASE-APP>.firebaseio.com/data"); // Save Data ref.setValue("Hello");  // Sync data ref.addValueEventListener(new ValueEventListener() {     @Override     public void onDataChange(DataSnapshot snapshot) {         System.out.println(snapshot.getValue());     }     @Override     public void onCancelled(FirebaseError firebaseError) {         System.out.println("The read failed: " + firebaseError.getMessage());     } }); 

FirebaseUI

The Firebase SDK is good at saving and retrieving data, but it is agnostic of Android SDK components like ListAdapters. For that you can use the FirebaseUI library.

FirebaseUI allows you to quickly connect common UI elements to the Firebase database for data storage. Below is an example of using FirebaseUI with a FirebaseListAdapter.

mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {     @Override     protected void populateView(View view, ChatMessage chatMessage) {         ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());         ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());      } }; messagesView.setListAdapter(mAdapter); 

That's just the gist of everything. The documentation of Firebase is pretty comprehensive (and human readable if I do so myself).

like image 197
David East Avatar answered Oct 12 '22 16:10

David East