Firebase OnSuccessListener in offline mode

Viewed 833

In Firebase addOnSuccessListener method will be called when the app in online mode. But it is not called when offline mode. Following is my code:

mFirebaseDatabase.setValue(newAreaModel)
    .addOnSuccessListener(new OnSuccessListener<Void>()
    {
        @Override
        public void onSuccess(Void aVoid)
        {
            finish();
        }
    })
    .addOnFailureListener(new OnFailureListener()
    {
        @Override
        public void onFailure(@NonNull Exception e)
        {
            Toast.makeText(getApplicationContext(), "Something went Wrong!", Toast.LENGTH_SHORT).show();
        }
    });

Now I want to finish the activity when setValue() method called in offline mode.

Can anyone suggest me how to do that?

2 Answers

When there is a loss of network connectivity (there is no network connection on user's device), neitheronSuccess() nor onFailure() methods are triggered. This has always been the behavior in the Firebase Realtime Database. Only writes that are committed on Firebase servers are considered succeeded or failed, before that they're pending.

Now I want to finish the activity when setValue() method called in offline mode.

Unfortunately, as far as I know, there is no event that triggers when the data has been written to the local queue.

Related