Android Application with firebase connectivty - android

If I create an android application which has firebase connection for database services, then is it necessary to have a internet connection to run and use the application?

The most important feature of Firebase Realtime Database is by far, the real-time feature. This means that you can stay in sync with the Firebase servers, to always get real-time updates. However, if there is no internet connection on the user's device, Firebase provides another very useful feature which is offline persistence. As in the official documentation, to enable this feature, you should simply use the following line of code:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
But remember, this feature works for short to intermediate periods of being disconnected. If you want to use an offline-only database, you might consider using a local database. For that I recommend you using the Room Library.

Related

Is spring boot required with Firebase for Android?

I'm really sorry if this is not the right place to ask such question, please refer me where I can ask if this is not.
I'm developing an Android application and using Firebase as backend to store data. I'm new to both Firebase and Springboot. I've been told to learn to create some basic APIs in SpringBoot but I have been question why I would need to.
From what I got to know, Firebase already provides an API for querying data that I might need to transfer. What is the use of SpringBoot? I've read it provides "easy-deployable" application and handles Unit and Integration Testing.
If I use SpringBoot on top of Firebase, isn't it redundant? Are there additional advantages that I'm missing?
SpringBoot is completely independent of Firebase.
Firebase is basically a service which is provided by Google so that the developer doesn't need to do server-side coding.
SpringBoot is a framework which is generally used for the development of the server-side application.
By using firebase you need to pay google for data storage and API usage stuff. If we compare using firebase & spring-boot application in terms of costing taking same amount of data storage, the amount you need to pay for firebase is a lot more. Though this amount is justified, as you don't need to write even a single line of code for server-end and all the server connections, data storage and security is maintained by firebase.
You can learn more about firebase on it's official website - https://firebase.google.com/
If you are starting, I would recommend you to learn and use SpringBoot rather than firebase. But if your application demands a real-time database, you must go for firebase to take care of that feature.
Here is an article for your reference Reasons Not To Use Firebase
Spring Boot is not required to use Firebase SDKs on Android. The Firebase SDKs operate completely independently of any backend you control.
If you want to provide Spring Boot backend for your Android app, that's completely up to you. Or whatever backend you want. The Firebase client SDKs don't care.

Google Cloud Firestore Sync Devices Data in Local Network (no internet temporally)

Google has launched Google Cloud Firestore. Just as they says...
"Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. Like Firebase Realtime Database, it keeps your data in sync across client apps through realtime listeners and offers offline support for mobile and web".
The question is...
In the application I am thinking about, needs that everyone to have data perfectly sync between devices (web and mobile). Ok, Firestore looks perfect for that.
* But what if my application also needs to sync between devices in a local network. Let's suppose if the internet connection is gone (whatever reasons...)*.
Does anyone could give me a direction how could it be made using Google Cloud Firestore (I don't mean the code). I use node for web application and Android for mobile.
Cloud Firestore as well as Firebase Reatime Database supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. So, if you are using:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
It means that Firestore will create a local copy of your database on your device, which in turn means that you'll be able to query your the database even if you are offline. So every change that is made while you are offline, will be updated on Firebase servers once you are back online. Unfortunately this local copy of your database cannot exist elsewhere than on your device. It cannot be hosted in a local network. Also all CRUD operation can be done only on the database which are hosted on users device.
Another thing to note, is that once the Internet connectivity is reestablished, you'll receive the appropriate current server state. The Firebase client synchronizes that data with the Firebase servers and with other clients that are using the same database. So, as a conclusion, in order to keep all your devices from a local network synced, you need to have internet access.

Firebase Storage Sync api

I am trying to develop an app whereby I want to exchange files (video, images) within the cloud storage(firebase) and client(android app).
I wanted to know if there is any sync API in firebase which keeps track of any updates i.e any changes being performed in the firebase storage and replicating the same to the client (and vice-versa if possible).
Thanks in advance !!
Go to the page of Firebase and read what the header says:
Store and sync data in real time
Furthermore:
The Firebase Realtime Database is a cloud-hosted NoSQL database that
lets you store and sync data between your users in real-time.
What Realtime means is this:
Instead of typical HTTP requests, the Firebase Realtime Database uses
data synchronization—every time data changes, any connected device
receives that update within milliseconds. Provide collaborative and
immersive experiences without thinking about networking code.
So just add Realtime Database Dependency and you are set. This itself will serve the purpose of Sync API you need.

Saving bandwidth for Firebase Realtime Database by enabling offline support

I wondering if enabling offline support in the clients for the Firebase Realtime Database saves you any bandwidth?
I wonder if the Firebase client when starting loads the database from storage and then continue on and only syncs the stuff that has been added later? Or does it sync everything and if that doesn't work fallbacks to the offline data that he has stored before.
If you are using FirebaseDatabase.getInstance().setPersistenceEnabled(true); means that you'll be able to query your the database even if you are offline. This is happening because Firebase creates a local copy of your database. Every change that is made while you are offline, will be updated on Firebase servers once you are back online. So this option is not used to save bandwidth, is to enable offline capabilities.
To be more clear, every client that is using a Firebase database and uses setPersistenceEnabled(true) maintains it's own internal (local) version of the database. When data is updated, it is first written to this local version of the database.
As a result, all writes to Firebase will trigger local events immediately, before any data has even been written to the server. This means that the app will remain responsive regardless of Internet connectivity.
Once the Internet connectivity is reestablished, you'll receive the appropriate current server state. The Firebase client synchronizes that data with the Firebase servers and with other clients that are using the same database.
Another thing to remember is that Firebase automatically manages connection state to reduce bandwidth and battery usage. When a client has no active listeners, no pending write or onDisconnect operations, and is not explicitly disconnected by the goOffline method, Firebase closes the connection after 60 seconds of inactivity.
As a conclusion, there is no difference regarding bandwidth when we are enabling offline support. The benefit is that we can query and change the database even if we are not connected to the internet.
Hope it helps.
I talked to a Googler today at Google Next Amsterdam and he confirmed the theory that I have.
If you have offline support enabled in your app and you are going from offline to online state, Firebase will sync your database in the smartest way possible. So that means that if it's possible it will only send over the changed values. So, enabling offline support does save you bandwidth.

Firebase instead of SQLite

I have been using SQLite as my storage solution for my android applications. I want to be able add synchronization functionality to one of my apps, Firebase looks like a good solution but the problem is that I need to know if I am to use Firebase to sync data with the SQLite database or Firebase can work and totally replace SQLite. I know Firebase has offline persistence but while offline can it hold as much data as SQLite and are the queries as powerful?
Clearly this depends on the business rules for which the options are considered. So there will not be the "right" answer to this.
At least one of our team members was thinking along these lines. Here is our solution:
Do all transactional data locally on the SQLite as we do not need transactions to be across devices.
Sync the rest using Firebase.
(1) makes sure that we don't misuse Firebase's non-persistent offline availability of its client.
The docs
Even with persistence enabled, transactions are not persisted across app restarts. So you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your app should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your app remembers them manually and executes them again after an app restart.
(2) make sure that we use Firebase's persistent offline nature to synch non-transactional data across devices once connection is (re)established.
The docs, The Firebase Realtime Database client automatically keeps a queue of all write operations that are performed while your app is offline. When persistence is enabled, this queue is also persisted to disk so all of your writes are available when the user or operating system restarts the app. When the app regains connectivity, all of the operations are sent to the Firebase Realtime Database server.
This way we achieve a state acceptable within our use.
"can it hold as much data as SQLite and are the queries as powerful?" no and no if powerful is translated as "transaction across devices", by definition of Firebase being a remote database.

Categories

Resources