Skip to content

Single....blockingGet() hangs in RxJava 2.1.3 when using Android/Firebase #5576

@bagintz

Description

@bagintz

When using the following pattern to synchronously get data from Firebase Realtime Database:

String s = Single.create(new SingleOnSubscribe<String>() {
	@Override
	public void subscribe(SingleEmitter<String> e) throws Exception {
		FirebaseDatabase.getInstance().getReference("path").orderByChild("child")
                     .equalTo("xyz").addListenerForSingleValueEvent(new ValueEventListener() {
    		@Override
    		public void onDataChange(DataSnapshot dataSnapshot) {
        		e.onSuccess("Got it");
    		}
    		@Override
    		public void onCancelled(DatabaseError databaseError) {
        		e.onError(databaseError.toException());
    		}
		});
	}
}).blockingGet();

It will hang and create an ANR error. If I use the same Firebase "innards" outside of the Single, it fires just fine. The Single without the Firebase code inside also will fire, so it seems there is some incompatibility between the two.

[Apologies on the formatting, I can't for the life of me get it to look nice]

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions