Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes crash due to Receiver not registered #430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ public void onReceive(Context context, Intent intent) {
}
}
};

context.registerReceiver(broadcastReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
observer.onSubscribe(Disposables.fromAction(new Action() {
@Override
public void run() throws Exception {
context.unregisterReceiver(broadcastReceiver);
}
}));
observer.onNext(locationProviderOk);
context.registerReceiver(broadcastReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ class LocationServicesOkObservableApi23Test extends RoboSpecification {
1 * contextMock.unregisterReceiver(registeredReceiver)
}

def "should register and unregister broadcast listeners in correct order if unsubscribed on the first emission"() {
given:
mockLocationServicesStatus.isLocationProviderOk() >> isLocationProviderOkResult

when:
objectUnderTest.take(1).test()

then:
1 * contextMock.registerReceiver(_, _)

then:
1 * contextMock.unregisterReceiver(_)

where:
isLocationProviderOkResult << [true, false]
}

def "should emit what LocationServicesStatus.isLocationProviderOk() returns on subscribe and on next broadcasts"() {

given:
Expand Down