Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tcw165/17ca5aa310d37235a62ee16b7cd390e2 to your computer and use it in GitHub Desktop.

Select an option

Save tcw165/17ca5aa310d37235a62ee16b7cd390e2 to your computer and use it in GitHub Desktop.
// Activity or Fragment
private val mResumeSignal = PublishSubject.create<Boolean>()
private val mResultSignal = PublishSubject.create<Any>()
override void onResume() {
super.onResume();
mResumeSignal.onNext(true);
}
override void onPause() {
super.onPause();
mResumeSignal.onNext(false);
}
override void onActivityResult(requestCode: Int,
resultCode: Int,
data: Intent) {
mResultSignal.onNext(...);
}
// Postpone the moment of sending the result to your Presenter or domain
// component regardless of handling save-restore
fun onGetResult(): Observable<Any> {
return TakeWhenObservable(src = mResultSignal,
whenSrc = mResumeSignal,
bufferSize = 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment