Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

Creating and Inserting Value in Firebase Realtime Database

Creating and Inserting Value in Firebase Realtime Database




  • Retrieve From database and show it on ListView Click Here
  • Update data in Database Click Here
  • Delete Data in Database Click Here



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
Firebase Assistant in Android Studio

  • Click Realtime Database from Assistant
Firebase Realtime Database in Android Studio Assistant

Firebase Realtime Database in Android Studio Assistant

  • 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
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
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
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
Set up Rules in Firebase Database


Then Finally run your app and add some data to show on your Database Table in Data Tab.

 
Follow us for more posts like this, 
Subscribe to Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

99 comments:

  1. As always as widespread contractors web dsign company, you are in inappropriate hands with those men!

    ReplyDelete
  2. Interesting 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

    ReplyDelete
  3. very 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

    ReplyDelete
  4. Positive 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.
    토토사이트

    ReplyDelete
  5. I like this post,And I guess that they having fun to read this post,they shall take a good site to make a information,thanks for sharing it to me.
    파워볼사이트

    ReplyDelete
  6. Thank 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.
    Roof Restoration Adelaide

    ReplyDelete
  7. 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! 먹튀사이트

    ReplyDelete
  8. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. i99pro

    ReplyDelete
  9. Great articles and great layout. Your blog post deserves all of the positive feedback it’s been getting. 안전놀이터

    ReplyDelete
  10. This is actually the kind of information I have been trying to find. Thank you for writing this information. cheap hosting in indiaonohosting

    ReplyDelete
  11. https://lianmeiting.blogspot.com/2014/12/studio-sands-pole-dancing-school.html?showComment=1625975529537#c1522390455532264158

    ReplyDelete
  12. Wow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon. here

    ReplyDelete
  13. Wow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon. 토토사이트

    ReplyDelete
  14. i am always looking for some free stuffs over the internet. there are also some companies which gives free samples. uwatchfree

    ReplyDelete
  15. 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! matka chart

    ReplyDelete
  16. Impressive 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

    ReplyDelete
  17. I really like your writing style, great information, thankyou for posting. Pollen Collection Price

    ReplyDelete
  18. I 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. 온라인슬롯

    ReplyDelete
  19. Merely a smiling visitant here to share the love (:, btw outstanding style. bolly4u

    ReplyDelete
  20. Cool stuff you have got and you keep update all of us. 안전놀이터

    ReplyDelete
  21. I am continually amazed by the amount of information available on this subject. What you presented was well researched and well worded in order to get your stand on this across to all your readers. 토토사이트

    ReplyDelete
  22. I’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... 무료릴게임

    ReplyDelete
  23. Wonderful 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

    ReplyDelete
  24. Everything has its value. Thanks for sharing this informative information with us. GOOD works! magicien mariage Lyon

    ReplyDelete
  25. 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! pussy888

    ReplyDelete
  26. Nice 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. 389sports

    ReplyDelete
  27. Great 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

    ReplyDelete
  28. This is actually the kind of information I have been trying to find. Thank you for writing this information. Filmygod

    ReplyDelete
  29. Join Public Mobile now with Public Mobile Promo Code E3LRK5 and get $10 off your cell phone bill using a Public Mobile Referral Code exclusively on Newsrooms. Newsrooms

    ReplyDelete
  30. Positive 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

    ReplyDelete
  31. Impressive 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

    ReplyDelete
  32. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. how to fix dull hair

    ReplyDelete
  33. This is actually the kind of information I have been trying to find. Thank you for writing this information. joker123

    ReplyDelete
  34. Cool stuff you have got and you keep update all of us. sbobet asia

    ReplyDelete
  35. Liposuction 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

    ReplyDelete
  36. Most patients want to have liposuction done by a specialist. A liposuction specialist is someone who performs this procedure almost daily. click here for more

    ReplyDelete
  37. An 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

    ReplyDelete
  38. Hi there! Nice stuff, do keep me posted when you post again something like this! 안전놀이터

    ReplyDelete
  39. 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.
    nex777 login
    nex777 login
    nex777 login
    nex777 login
    nex777 login
    sip777 login

    ReplyDelete
  40. thanks for this usefull article, waiting for this article like this again. 팔팔카

    ReplyDelete
  41. This is actually the kind of information I have been trying to find. Thank you for writing this information. บาคาร่าออนไลน์

    ReplyDelete
  42. howdy, your websites are really good. I appreciate your work. 먹튀검증

    ReplyDelete
  43. A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. 대전1인샵

    ReplyDelete
  44. Nice post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part I care for such information a lot. I was seeking this certain info for a long time. Thank you and good luck. 먹튀검증

    ReplyDelete
  45. Excellent 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! 토토커뮤니티

    ReplyDelete
  46. A great content material as well as great layout. Your website deserves all of the positive feedback it’s been getting. I will be back soon for further quality contents. 토토커뮤니티

    ReplyDelete
  47. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. 먹튀검증

    ReplyDelete
  48. It 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. 먹튀폴리스

    ReplyDelete
  49. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. 온라인바둑이

    ReplyDelete
  50. Wonderful article. Fascinating to read. I love to read such an excellent article. Thanks! It has made my task more and extra easy. Keep rocking. 바둑이

    ReplyDelete
  51. I would recommend my profile is important to me, I invite you to discuss this topic. 토토사이트

    ReplyDelete
  52. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! 토토사이트

    ReplyDelete
  53. Thanks 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. 꽁나라

    ReplyDelete
  54. The way you write, you are really a professional blogger. YesMovies

    ReplyDelete
  55. Wow! 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. 토토사이트

    ReplyDelete
  56. A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. IBCBET

    ReplyDelete
  57. This 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. 토토커뮤니티

    ReplyDelete
  58. Nice post mate, keep up the great work, just shared this with my friendz 토토사이트

    ReplyDelete
  59. I love visiting sites in my free time. I have visited many sites but did not find any site more efficient than yours. Thanks for the nudge! Nagaland State Lottery

    ReplyDelete
  60. Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work. 먹튀검증

    ReplyDelete
  61. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. ufabet

    ReplyDelete
  62. I have read your article couple of times because your views are on my own for the most part. It is great content for every reader. บาคาร่าออนไลน์

    ReplyDelete
  63. Thanks 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. 오피아트

    ReplyDelete
  64. You have outdone yourself this time. It is probably the best, most short step by step guide that I have ever seen. หน้าหมอง

    ReplyDelete
  65. An 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. เอสเซ้นส์

    ReplyDelete
  66. This 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

    ReplyDelete
  67. Nice 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 สายเทา

    ReplyDelete
  68. Tahir termite service – TTS® is the largest independently owned pest control company in Lahore, Pakistan.Pest Control Lahore

    ReplyDelete
  69. Effective and reliable protection for your teeth The brush handle fits perfectly in the hand, is slim and beautifully made.Curtains online Price In pakistan

    ReplyDelete
  70. Salon is now proud to offer complete range of hair styling, facial skincare treatments and body hair removal services for men.bridal makeup packages in karachi

    ReplyDelete
  71. We have the best and premium service portfolio that makes us the right and best choice for you.Pest Control near me

    ReplyDelete
  72. Kbc Lottery Winner 2022 list for information online like Kaun Banega Crorepati Lucky draw Winners 2022.Kbc lottery winner

    ReplyDelete
  73. We have the best and premium service portfolio that makes us the right and best choice for you.Pest Control sargodha

    ReplyDelete
  74. Kbc official website list for information online like Kaun Banega Crorepati Lucky draw Winners 2022.Jio lottery office number 2022

    ReplyDelete
  75. We have the best and premium service portfolio that makes us the right and best choice for you.Termite Treatment sargodha

    ReplyDelete
  76. We offer specialised sameday courier services to firms in a variety of industrial sectors to and from any UK location.Courier service in london

    ReplyDelete
  77. I 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

    ReplyDelete
  78. buy 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

    ReplyDelete
  79. Kbc winner list 2022 Its a big concern for people to proceed with their participation cases with the right information because of the rising cases of fraud. So, its extremely eminent to get an authentic Kaun Banega Crorepati Office Number for the right guidance about the kbc plans.Kbc winner list 2022

    ReplyDelete
  80. Termite 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

    ReplyDelete
  81. Deemak 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

    ReplyDelete
  82. We provide Kbc lottery winner 2022 Mumbai and Kbc lottery winner season 13 data online. Lucky Winners 2022.Kbc lottery winner

    ReplyDelete
  83. This 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

    ReplyDelete
  84. After 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! 사설토토

    ReplyDelete
  85. This 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 ... 토토사이트

    ReplyDelete
  86. Through 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! 룰렛

    ReplyDelete
  87. I'm truly intrigued that there is such a lot of data about this subject that have been revealed and you've put forth a valiant effort, with such a lot of class. I was suggested this blog by my cousin. I'm uncertain about whether this post is composed by him as no one else know such point by point about my trouble. You're great! Much obliged! Noteworthy site, Distinguished input that I can handle. Im pushing ahead and may apply to my present place of employment as a pet sitter, which is truly pleasant, however I need to extra extend. Recognizes for paper a particularly advantageous organization, I staggered adjacent to your blog other than translate a restricted declare. I need your method of engraving.. 토토

    ReplyDelete
  88. Work 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. 먹튀검증백과

    ReplyDelete
  89. Interesting 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. 메이저놀이터

    ReplyDelete
  90. 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! 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 카이소

    ReplyDelete
  91. Decent 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. 오래된토토사이트

    ReplyDelete
  92. I 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 토토디펜드

    ReplyDelete
  93. You 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."

    ReplyDelete
  94. BubzyRecruitment is the construction staffing agency of choice for world-leading infrastructure businesses.construction recruitment agencies Aberdeenshire

    ReplyDelete
  95. Ultrasound Supplies Simplibuy is your online one-stop resource for buying medical supplies, diagnostic equipment and accessories.GTA Medical Supplies

    ReplyDelete
  96. There are so many fun apps to download and enjoy right now. If you love watching movies and shows, there are plenty of streaming apps you can download right now.;manhwaland

    ReplyDelete
  97. Thanks for fantastic information I was looking for this information for my mission.
    play game for relax and win get money
    PG SLOT

    ReplyDelete
  98. If I had found your post a little earlier, my presentation material would have been richer. 토토사이트

    ReplyDelete