Last active
January 7, 2017 19:40
-
-
Save Diolor/43d385f0fe22373f5010d464411d0932 to your computer and use it in GitHub Desktop.
Controllable observable with commit()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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