Creating and Inserting Value in Firebase Realtime Database
Creating and Inserting Value in Firebase Realtime Database
Firebase Realtime Database is an online database used for the android app and it's free of cost but with some limits.
Today, we create a Firebase Realtime database and Insert some values in it.
- Create a project in Android Studio.
- After a successful build, open Tools from the menu and click on Firebase.
Firebase Assistant in Android Studio |
- Then Connect your Database and Click on Add Realtime Database to add required dependencies in your project
Connect and Add Firebase Dependencies in Android project |
Then Setup your activity_main.xml
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll No"
android:id="@+id/student_roll"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/student_name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Std"
android:id="@+id/student_std"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Student"
android:id="@+id/add_btn"/>
</LinearLayout>
Then Create a Model Class
Student_Model.java
package studio.harpreet.firebasedatabase;
import androidx.annotation.Keep;
@Keep // when you want to publish your apk to Google play store, because proguard not add some java files
public class StudentModel {
String id, rollno,name,std;
public StudentModel() {
}
//Shortcut is alt+insert
public StudentModel(String id, String rollno, String name, String std) {
this.id = id;
this.rollno = rollno;
this.name = name;
this.std = std;
}
public String getId() {
return id;
}
public String getRollno() {
return rollno;
}
public String getName() {
return name;
}
public String getStd() {
return std;
}
}
Then Setup your MainActivity.java
MainActivity.java
package studio.harpreet.firebasedatabase;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
DatabaseReference databasestudent;
EditText roll_et,name_et,std_et;
Button add_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
roll_et = findViewById(R.id.student_roll);
name_et = findViewById(R.id.student_name);
std_et = findViewById(R.id.student_std);
add_btn = findViewById(R.id.add_btn);
databasestudent = FirebaseDatabase.getInstance().getReference("Student");
add_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addstudent(roll_et.getText().toString().trim(),
name_et.getText().toString().trim(),
std_et.getText().toString().trim());
}
});
}
private void addstudent(String Rollno, String Name, String Std)
{
String id = databasestudent.push().getKey();
StudentModel studentModel = new StudentModel(id,Rollno,Name,Std);
databasestudent.child(id).setValue(studentModel);
}
}
Then we have to add googleservices.json file which we can download from firebase project settings.
Download googleservices.json file from firebase realtime database |
Then change your view from android to project view and paste googleservices.json under the app section.
Add Google Services.json file to Android project |
Then click on Database from the left menu in Firebase Console
Change your rules to true to add and access values from the database. we will talk about security of rules in our next post.
Set up Rules in Firebase Database |
Then Finally run your app and add some data to show on your Database Table in Data Tab.
Subscribe to Harpreet studio on Youtube
Like Harpreet Studio on Facebook
Follow me on Instagram
As always as widespread contractors web dsign company, you are in inappropriate hands with those men!
ReplyDeleteInteresting and amazing how your post is! It Is Useful and helpful for me That I like it very much, and I am looking forward to Hearing from your next.. création de site internet
ReplyDeletevery interesting post.this is my first time visit here.i found so mmany interesting stuff in your blog especially its discussion..thanks for the post! WordPress Developer Brisbane
ReplyDeleteThank you for some different informative blog. Wherein else may want to I am getting that kind of facts written in such an ideal approach? I have a challenge that I’m simply now operating on, and i have been on the appearance out for such records.
ReplyDeleteRoof Restoration Adelaide
Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! 먹튀사이트
ReplyDeleteThis is actually the kind of information I have been trying to find. Thank you for writing this information. cheap hosting in indiaonohosting
ReplyDeletehttps://lianmeiting.blogspot.com/2014/12/studio-sands-pole-dancing-school.html?showComment=1625975529537#c1522390455532264158
ReplyDeletei am always looking for some free stuffs over the internet. there are also some companies which gives free samples. uwatchfree
ReplyDeleteGood website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! matka chart
ReplyDeleteImpressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards. Watergardens at Canberra Price
ReplyDeleteI really like your writing style, great information, thankyou for posting. Pollen Collection Price
ReplyDeleteI can’t believe focusing long enough to research; much less write this kind of article. You’ve outdone yourself with this material without a doubt. It is one of the greatest contents. 온라인슬롯
ReplyDeleteMerely a smiling visitant here to share the love (:, btw outstanding style. bolly4u
ReplyDeleteCool stuff you have got and you keep update all of us. 안전놀이터
ReplyDeleteI’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... 무료릴게임
ReplyDeleteWonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. pengeluaran sgp
ReplyDeleteEverything has its value. Thanks for sharing this informative information with us. GOOD works! magicien mariage Lyon
ReplyDeleteGood website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! pussy888
ReplyDeleteGreat post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. https://sites.google.com/view/hotmail-loginsigup/hotmail-login
ReplyDeleteThis is actually the kind of information I have been trying to find. Thank you for writing this information. Filmygod
ReplyDeletePositive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. buy packwoods marathon Uncle sam OG
ReplyDeleteImpressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards. best payment processing companies to work for
ReplyDeleteGreat post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. how to fix dull hair
ReplyDeleteThis is actually the kind of information I have been trying to find. Thank you for writing this information. joker123
ReplyDeleteCool stuff you have got and you keep update all of us. sbobet asia
ReplyDeleteLiposuction is a vacuum cleaner for fat. With unparalleled safety and minimal discomfort, the surgeon uses a pump to suck out unwanted areas of fat. Click Here
ReplyDeleteMost patients want to have liposuction done by a specialist. A liposuction specialist is someone who performs this procedure almost daily. click here for more
ReplyDeleteAn interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. 123 movies
ReplyDeleteHi there! Nice stuff, do keep me posted when you post again something like this! 안전놀이터
ReplyDeleteThere is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way.
ReplyDeletenex777 login
nex777 login
nex777 login
nex777 login
nex777 login
sip777 login
This is actually the kind of information I have been trying to find. Thank you for writing this information. บาคาร่าออนไลน์
ReplyDeletehowdy, your websites are really good. I appreciate your work. 먹튀검증
ReplyDeleteA very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. 대전1인샵
ReplyDeleteExcellent website! I adore how it is easy on my eyes it is. I am questioning how I might be notified whenever a new post has been made. Looking for more new updates. Have a great day! 토토커뮤니티
ReplyDeleteIt is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post. 먹튀폴리스
ReplyDeleteWonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. 바둑이
ReplyDeleteI would recommend my profile is important to me, I invite you to discuss this topic. 토토사이트
ReplyDeleteThanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again. 꽁나라
ReplyDeleteWow! This could be one of the most useful blogs we have ever come across on thesubject. Actually excellent info! I’m also an expert in this topic so I can understand your effort. 토토사이트
ReplyDeleteA very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. IBCBET
ReplyDeleteThis type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. 토토커뮤니티
ReplyDeleteNice post mate, keep up the great work, just shared this with my friendz 토토사이트
ReplyDeleteThanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. 오피아트
ReplyDeleteYou have outdone yourself this time. It is probably the best, most short step by step guide that I have ever seen. หน้าหมอง
ReplyDeleteAn interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. เอสเซ้นส์
ReplyDeleteThis article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. ทางเข้า ufabet
ReplyDeleteNice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share. รับทำ seo สายเทา
ReplyDeleteWe have the best and premium service portfolio that makes us the right and best choice for you.Termite Treatment sargodha
ReplyDeleteI think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. homestay melaka with swimming pool
ReplyDeletebuy instagram views Boost Social Media promises its clients authentic and real followers with instant delivery so that you can have your business up and running. The varying range of high-quality followers that we offer our clients, guarantees you a safe and sound account.buy instagram views
ReplyDeleteTermite Proofing sargodha We are offering you trusted services with the experience of 21 years and counting. Tahir Termite service is serving you with a dedicated team of professionals, along with latest equipment and technology.Termite Spray sargodha
ReplyDeleteDeemak Control sargodha Tahir termite control service believes in providing you ultimate services. We are the best termite killers in Lahore. By taking care of your safety, construction site and other essentials, we process the treatment.Termite Control service sargodha
ReplyDeleteWe provide Kbc lottery winner 2022 Mumbai and Kbc lottery winner season 13 data online. Lucky Winners 2022.Kbc lottery winner
ReplyDeleteThis is really intriguing, You’re an especially efficient writer. I have signed up with your feed additionally look ahead to finding your personal interesting write-ups. Furthermore, I’ve got shared the blog inside our social networks. canaan avalon 1246
ReplyDeleteAfter study a few of the blog articles with your website now, we truly such as your way of blogging. I bookmarked it to my bookmark site list and you will be checking back soon. Pls take a look at my site likewise and tell me if you agree. I am often to blogging i actually appreciate your posts. The article has really peaks my interest. My goal is to bookmark your web blog and keep checking choosing info. Excellent post however , I was wanting to know if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit more. Bless you! 사설토토
ReplyDeleteThis is an awesome article, Given such an extraordinary measure of data in it, These sort of articles keeps the customers excitement for the site, and keep sharing more ... favorable circumstances. Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up. The most intriguing content on this fascinating point that can be found on the net ... 토토사이트
ReplyDeleteThrough this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity . There is so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way. Writing with style and getting good compliments on the article is quite hard, to be honest.But you've done it so calmly and with so cool feeling and you've nailed the job. This article is possessed with style and I am giving good compliment. Best! 룰렛
ReplyDeleteWork Is Not Longer A Place Pay safely using our Payment system, release payments according to a schedule of milestones you set, or pay only upon completion. You are in control, so you get to make decisions . Interesting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon. this is really interesting reading. I am glad I found this and got to read it. Great job on this content. I like it. 먹튀검증백과
ReplyDeleteInteresting post. I Have Been wondering about this issue. so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks . We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up . I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more. 메이저놀이터
ReplyDeleteWriting with style and getting good compliments on the article is quite hard, to be honest.But you've done it so calmly and with so cool feeling and you've nailed the job. This article is possessed with style and I am giving good compliment. Best! I think this is one of the most significant information for me. And i'm glad reading your article. I ought to say that, as much as I loved hearing what you might have to say, I got bored after a while. Stay updated for detailed and thorough instructions if you're looking for the best . Very informative post ! There is a lot of information 카이소
ReplyDeleteDecent read, I just passed this onto a companion who was doing a little research on that. Also, he really got me lunch since I discovered it for him grin So let me reword that: Thank you for some other enlightening online journal. What other place could I get that kind of data written in a particularly ideal methods? I have a mission that I'm seconds ago dealing with, and I have been at the post for such data . Eminently composed article, if just all bloggers offered a similar substance as you, the web would be an obviously better spot. It's exceptionally instructive and you are clearly entirely proficient around here. You have made me fully aware of differing sees on this subject with fascinating and strong substance. 오래된토토사이트
ReplyDeleteI can’t believe focusing long enough to research; much less write this kind of article. You’ve outdone yourself with this material without a doubt. It is one of the greatest contents. I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it . This is a great article, Given such a great amount of information in it, These kind of articles keeps the clients enthusiasm for the site, and continue sharing more ... Thanks for sharing great information. It is nice to read such high-quality content. Thanks for the post 토토디펜드
ReplyDeleteYou completed some fine points there. I did a search on the matter and found most persons will consent with your blog."does wendy's take apple pay You made several nice points there. I did a search on the subject and found mainly folks will have the same opinion with your blog."
ReplyDeleteBubzyRecruitment is the construction staffing agency of choice for world-leading infrastructure businesses.construction recruitment agencies Aberdeenshire
ReplyDelete토토검증사이트 Soccer statistics websites Whoscored.com and Sofascore both listed Cho on their teams of the World Cup second round, reflecting the round's top players.
ReplyDelete사설토토 Turkey's Fenerbahce SK and France's Stade Rennais have also reportedly contacted Lee about Cho.
ReplyDelete먹튀검증커뮤니티 In 2020, he joined Jeonbuk Hyundai Motors, which competes in K League 1, Korea's top tier of soccer. He was K League 1's joint top scorer in the 2022 season, which ended on Oct. 29, with 17 goals, sharing the title with Min Kyu-joo of Jeju United.
ReplyDelete카지노사이트 After scoring his team's two goals against Ghana ― the first time a Korean player had scored two goals in a single World Cup game ― his number of followers spiked to nearly 1.5 million.
ReplyDelete카지노커뮤니티 As of Dec. 1, the 24-year-old's Instagram account with only five posts had more than 1.6 million followers. Before the World Cup, he had only 20,000.
ReplyDelete토토사이트 Born on Jan. 25, 1998, Cho was considered too slim to be an attacker just two years ago; at 1.88 meters tall and 77kg (170lb) he was called "anchovy," a common nickname for skinny people in South Korea. But after joining the army, he added weight and now tips the scales at 82kg.
ReplyDelete슬롯머신사이트 With the Hong Kong media already referring to Cho as the latest "man-god" from Korea, top commercial brands are sure to be going after him soon too, if not already.
ReplyDelete나는 그것의 굉장한 것을 말해야한다! 블로그는 정보를 제공하며 항상 놀라운 것을 생산합니다. 카지노사이트
ReplyDeleteSharing your cell phones can be risky. But with I-Cell Station's trustworthy services,
ReplyDeleteA blog is a discussion or informational website published on the World Wide Web consisting of discrete,
ReplyDeleteConstructing a house in DHA (Defence Housing Authority) Karachi is a popular dream
ReplyDeleteDigital Marketing USA, a digital marketing agency in USA,
ReplyDeleteWe deliver big ideas and even bigger results with more agility and efficiency than
ReplyDeleteHence, people miss out on the most essential part of the sales process.
ReplyDeleteE-Biz, a leading digital marketing agency, commenced its journey in Ireland as
ReplyDeleteWe aim to work in partnership with our clients and build a good working
ReplyDeleteOur team has experience bringing in both e-commerce sales as well as service leads.
ReplyDelete