Reputation: 31
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","[email protected]");
}
public void writeNewUser(String userId, String name, String email) {
User user = new User(name, email);
mDatabase.child("users").child(userId).setValue(user);
}
Upvotes: 1
Views: 864
Reputation: 1
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.
Upvotes: 0
Reputation: 31
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.
Upvotes: 2