0

I created a project and add my app to it recently. I'm already set Rule: Read and Write to true and tried a simple code to add new Value to Real Time Database console. But nothing happened. The console didn't get anything.

Here is the code i use;

FirebaseDatabase database = FirebaseDatabase.getInstance();

DatabaseReference ref = database.getReference("Bob");

ref.setValue(editText.getText.toString);

I did try ref.addValueEventListener and in onDataChange is textView.setText(snapshot.getValue(String.class)); The textView changes everytime I send data, even when i turn off the Wifi. Is it a problem lol?

Then I created a whole new application and tried the same code, it worked very well. But i can't leave the old app to move to the new one because i have developed it for months.

I tried to copy 2 gradle file, manifest.xml from the old one to the new one. But the new one still work.

I also tried to remove and create new Firebase project, remove Firebase from the app and add to it again.

Has anyone ever been in this situation like me?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Dep1111
  • 93
  • 4

1 Answers1

1

My guess is that you downloaded the google-services.json file for the first app before you created the database. In that case the file does not contain the database URL, and the SDK can't guess it.

The fact that the local writes and reads still work is (in that case) because Firebase explicitly ensures that the local client sees its own changes, so that the app works even when the device intermittently loses its network connection.

So if the above is indeed the cause of the problem, you can take either of these steps to fix it:

  • Download an up to date google-services.json and use that in your app.
  • Explicitly specify the URL of your database in: FirebaseDatabase database = FirebaseDatabase.getInstance("URL here");

Also see: Google Firebase Real-time Database Not Working as everything is set correctly

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807