Skip to content

Instantly share code, notes, and snippets.

@Diolor
Last active January 7, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diolor/43d385f0fe22373f5010d464411d0932 to your computer and use it in GitHub Desktop.
Save Diolor/43d385f0fe22373f5010d464411d0932 to your computer and use it in GitHub Desktop.
Controllable observable with commit()
public class MainActivity extends AppCompatActivity {
private final PublishSubject<Object> dialogDisplaySubject = PublishSubject.create();
private final Disposable disposable = dialogDisplaySubject
.subscribe(o ->
new MyDialogFragment()
.show(getSupportFragmentManager(), "DIALOG_TAG")
);
@Override
protected void onPause() {
super.onPause();
dialogDisplaySubject.onNext(new Object()); // safe to call
}
@Override
protected void onSaveInstanceState(Bundle outState) {
dialogDisplaySubject.onNext(new Object()); // safe to call
super.onSaveInstanceState(outState);
dialogDisplaySubject.onNext(new Object()); // not safe to call, IllegalStateException
}
@Override
protected void onStop() {
dialogDisplaySubject.onNext(new Object()); // not safe to call, IllegalStateException
super.onStop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment