0

I am trying to add documents to Firebase Firestore from my android app. This is the code that I currently have.

FirebaseFirestore db = FirebaseFirestore.getInstance();


Map<String, Object> newuser = new HashMap<>();
        newuser.put("Username",username);
        newuser.put("Password",password);
        newuser.put("Nickname",userNickname);
        newuser.put("Code", "ffff");
        newuser.put( "Othercode", "ffffffff");
        newuser.put("Age", "0");
        
        //Point 1

        db.collection("Users").document(username).set(newuser)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        //Point 2
                    }
                })

                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        //Point 3
                    }
                });
//Point 4

When I run this code it will reach Point 1 and Point 4, but never Point 3 or Point 2. I'm pretty new to android and java so I'm not sure what the things in the Logcat mean either:

2020-09-05 09:53:53.514 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:53:55.391 19216-19242/com.example.app W/e.librarysearc: Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
2020-09-05 09:54:27.236 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:27.260 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:33.134 19216-19216/com.example.app W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@12d6200
2020-09-05 09:54:33.417 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:35.895 19216-19328/com.example.app W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}
2020-09-05 09:54:36.271 19216-19216/com.example.app W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@549ad31
2020-09-05 09:54:36.572 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:36.814 19216-19328/com.example.app W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}
2020-09-05 09:54:42.040 19216-19216/com.example.app I/AssistStructure: Flattened final assist data: 3832 bytes, containing 1 windows, 12 views
2020-09-05 09:54:43.993 19216-19216/com.example.app I/AssistStructure: Flattened final assist data: 3832 bytes, containing 1 windows, 12 views
2020-09-05 09:54:45.386 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:45.408 19216-19245/com.example.app I/chatty: uid=10091(com.example.librarysearch) RenderThread identical 1 line
2020-09-05 09:54:45.437 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:51.060 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)
2020-09-05 09:54:51.079 19216-19245/com.example.app D/EGL_emulation: eglMakeCurrent: 0xe9c85300: ver 3 0 (tinfo 0xe9c83650)

It was functioning, but suddenly it stopped working, so I'm not sure what I did. If you need any more code, I can provide it as well. Thank you in advance!

Olivia
  • 1
  • 4

2 Answers2

0

You probably need to Wipe Data from the current AVD you are using and try running it agian.

I think that the AVD Internet wasn't working correctly, or too much was running on it so when I wiped the data this was solved. I don't think that this can happen on a real device, but I'm not sure. Hopefully this is works for anyone else with this issue.

Olivia
  • 1
  • 4
0

I had the same problem and for me it was the emulator. I've downgraded it to v31.2.10 and all the attempts when the inserts didn't work to the Firestore completed after the downgrade.

Read more here: Firebase doesn't work on Android Studio Emulator!

You can get older emulator versions from https://developer.android.com/studio/emulator_archive

Ady P
  • 1