Star_Man
Star_Man

Reputation: 1091

Firebase RealtimeDatabase is not working now?

Now Firebase RealtimeDatabase "write" is now working.

Here is the firebase sample code.

FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference("message");

        myRef.setValue("Hello, World!");

        myRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                // This method is called once with the initial value and again
                // whenever data at this location is updated.
                String value = dataSnapshot.getValue(String.class);
                Log.d(TAG, "Value is: " + value);
            }

            @Override
            public void onCancelled(DatabaseError error) {
                // Failed to read value
                Log.w(TAG, "Failed to read value.", error.toException());
            }
        });

ValueEventListener's onDataChange is called, but I can't find the written data in realtime database of firebase console.

Besides, apps of using realtime database made earlier does not behave today.

Is this a bug of firebase? What can I do now?

PS: Here is the log messages.

10-14 18:19:52.730 15916-15916/com.example.star_man.firebaserealtimedatabase V/FA: onActivityCreated
10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: Do partial code cache collection, code=61KB, data=47KB
10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: After code cache collection, code=61KB, data=47KB
10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: Increasing code cache capacity to 256KB
10-14 18:19:55.549 15916-15935/com.example.star_man.firebaserealtimedatabase I/art: Starting a blocking GC Instrumentation
10-14 18:19:56.858 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Using measurement service
10-14 18:19:56.860 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Connecting to remote service
10-14 18:19:56.872 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Activity resumed, time: 5619167420
10-14 18:19:56.876 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: ThreadedRenderer.create() translucent=false
10-14 18:19:56.884 15916-15916/com.example.star_man.firebaserealtimedatabase D/InputTransport: Input channel constructed: fd=80
10-14 18:19:56.886 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: setView = DecorView@304ed89[MainActivity] touchMode=true
10-14 18:19:56.905 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: dispatchAttachedToWindow
10-14 18:19:56.949 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1440,2560] result=0x27 surface={isValid=true 525456977920} surfaceGenerationChanged=true
10-14 18:19:56.951 15916-15982/com.example.star_man.firebaserealtimedatabase D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000,  [1440x2560]-format:1
10-14 18:19:56.951 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 525456977920} hwInitialized=true
10-14 18:19:56.981 15916-15970/com.example.star_man.firebaserealtimedatabase D/FA: Connected to remote service
10-14 18:19:56.981 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Processing queued up service tasks: 1
10-14 18:19:57.033 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
10-14 18:19:57.033 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1
10-14 18:19:57.035 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 525456977920}
10-14 18:19:57.038 15916-15916/com.example.star_man.firebaserealtimedatabase V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@eceb89a nm : com.example.star_man.firebaserealtimedatabase ic=null
10-14 18:19:57.038 15916-15916/com.example.star_man.firebaserealtimedatabase I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus
10-14 18:19:57.051 15916-15916/com.example.star_man.firebaserealtimedatabase D/InputTransport: Input channel constructed: fd=85
10-14 18:20:01.990 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Inactivity, disconnecting from the service

Upvotes: 1

Views: 391

Answers (2)

Star_Man
Star_Man

Reputation: 1091

The reason was the firewall of our company. But I don't know why onDataChange callback function was called. I think onCancelled callback function should be called.

Anyway, I modified the firewall rule, and now it is working well.

Upvotes: 1

Faruk
Faruk

Reputation: 5821

Try to put OnComplete Listener, is it called?

myRef.setValue("Hello, World!", new DatabaseReference.CompletionListener() {
  @Override
  public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
    if (databaseError != null) {
        Log.d("saving","Data could not be saved " + databaseError.getMessage());
    } else {
        Log.d("saving","Data saved successfully.");
    }
  }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
        Log.e("saving","Saving failed: " + e.getMessage());
    }
});

Upvotes: 1

Related Questions