简体   繁体   中英

data not inserting into firebase realtime database

The code executes without any error but firebase realtime database shows:-

testapp-a212c-default-rtdb: null

I have created the model class User. How do I insert data into firebase realtime database?

public class MainActivity extends AppCompatActivity {

private DatabaseReference mDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    mDatabase = FirebaseDatabase.getInstance().getReference();
    writeNewUser("123","asdf","asdf@gmail.com");
 }

 public void writeNewUser(String userId, String name, String email) {
    User user = new User(name, email);

    mDatabase.child("users").child(userId).setValue(user);
}

To get a reference to a database other than a us-central1 default dstabase, you must pass the database URL to getInstance() (or Kotlin+KTX database()). For a us-central1 default database, you can call getInstance() (or database) without arguments.

I was using SouthAsia Database.

In my case, I forgot to insert stream: FirebaseAuth.instance.onAuthStateChanged, in main.dart file. Which is ended up with uploading data to firebase Real Time Database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM