Android’s Database
You might be curious about the main objective behind this article ,yes you need to ,that’s how humans meant to be :D
With no delay I will be revealing it !
In this article, I am going to discuss about various ways of storing data from an app which is built on Android studio .This article is highly recommended for Android beginners and if you are an advanced guy then no worries , this will help you to brush up your skills.
Moreover, I made this as open source, if you are aware of some other ways you can contribute to this repository!! After all,this is how community grows:)
Let’s start with some introduction guys!!
We all know that for any tool, either an "APP" or "WEBSITE", database is the back. Quite common point once you know the importance of database for android.
It’s time to look into some detail version.
Majorly , data is stored in firebase and SQLite though there are ’n’ number of ways for storing,mysql and Node JS are one among them.
Do you want to know the reasons for being so popular?
Here goes the answer ,
Both Firebase and SQLite are highly supported by Google . Firebase is a rapidly developing database platform by Google with lots of features like authentication ,realtime database and SQLite is an inbuild database for Andriod and there is an official documentation present at Google developers site.
Now,let’s get into our business xD!!
Storing data from two activities using Firebase real time database.
STEP 1: Connecting up firebase to our project:
Firstly after creating a new project, go to tools and then to Firebase . Later , a firebase assistant will be opened showing various features offered by Firebase.Currently, we will be choosing a “Real Time Database” as we are dealing with it.After doing that, save and retrive option will be shown,again click on that . Later, two more options will be displayed.
Firstly, click on “Connect to Firebase” and let Andriod studio do it’s work. After that click on “Add the Realtime Database to your app”. You will be displayed something like below:
It’s not done yet!!
Now,open build.gradle file and change the database version to current firebase version . At the time of writing this article it’s 17.0.0 which is clearly shown in the highlighted text.
You can check your version from Firebase website itself.
STEP 2:Open your project in firebase:
Just simply follow up the GIF given below, it’s understandable and easy to follow up!
Note: I used test app to read and write the database as it’s only in development stage not in deployment.
STEP 3:Writing up the code : the heart of database
We can write the code in multiple ways by using various concepts and logics.For time being, I am writing up only one!
DEMO OF MY APP!!(Don’t mind the UI😅)
As already stated, I will be storing data from two activities. So I used two activities :
1)To get name
2)To get place
Here are the xml code pictures of both the activities:
LOGIC FOLLOWED:
Initially,stored data from the first activity by creating model class and later updated the same child by using the id number which I passed through the intent from first activity to second one!Remember there are also some other ways for doing the same.
MODEL CLASS CODE:
FIRSTACTIVITY.JAVA
SECONDACTIVITY.JAVA
Yeah!
Get TEJASWI KARASANI’s stories in your inbox
Join Medium for free to get updates from this writer.
You are right!We are done !
Aren’t you excited to know the second one?
Let’s quickly start that one though.
SQLite is also a perferrable option to store data but it’s not a “REALTIME DATABASE” rather just a database where every time after each updation,we need to save data and open it in a separate browser . Despite of disadvantage, it has it’s own advantages like no internet connectivity required which is a must and should requirement for firebase and very much comfortable for all the developers who knows SQL language.
STEP 1:Download DB Brower(SQLite) from the link
STEP 2:Start writing code :3
Isn’t it so simple while compared to Firebase?Just completed our work with in two steps.
DEMO OF MY APP!!(Again Don’t mind the UI 😅)
As already stated, I will be storing data from two activities . So I used two activities :
1)To get name
2)To get place
Here are the xml code pictures of both the activities:
LOGIC FOLLOWED:
Here , all the data will be written into database from the second activity (i.e)both the data belonging to first activity and second !!
You might be thinking that why can’t we use alter table query and store data from first activity initially and later for second??
Well! I would like to tell that technique will not work out buddy ☹
Although there are some other ways to do😁.
Go quickly check out the picture what happens if we use “ALTER”.
So,again I used one of my favourite concepts called “Intent” and with the help of this I had passed name from the first activity to second activity and then I used “ insert into” query and stored the data at a time and one more advantage over here is no need any model class.
FIRSTACTIVITY.JAVA
SECONDACTIVITY.JAVA
Now , it’s time to end my article.
Opps!!! Wait , we missed out some thing . We haven’t checkout the data produced.
The GIF below shows us how to save the dataset .
After saving it, we have to navigate to the desired file location and open the it from the DB Brower(SQLite).
This is how our database table look like!
Hope this blog helped you! Don’t forget to contribute to the repository if you follow some other concepts and logics to store data.
https://github.com/TejaswiKarasani/Android-s-database
You can shower up your blessings to this tech blog beginner by clapping ,it would take only 2 seconds to give 50 claps.
If you feel something is wrong or if I missed out one just mention in the comments, always happy to hear it from you.
You can connect with me through any of the platforms mentioned below if you need any help or for no reason you can, after all we live in the same community and connecting makes that community to grow vast!
LinkedIn : https://www.linkedin.com/in/tejaswi-karasani-28a944146
GitHub : https://github.com/TejaswiKarasani
Facebook : https://www.facebook.com/tejaswireddy.karasani
Instagram : https://www.instagram.com/tant129/










