Created
September 30, 2018 13:39
-
-
Save sellmair/cd56842eb7f5c78522f6ae562cac646f to your computer and use it in GitHub Desktop.
Disposing on Android 3
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
private lateinit var textView: TextView | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
textView = findViewById(R.id.text_view) | |
} | |
override fun onStart() { | |
super.onStart() | |
// Example 1 | |
DummyNetwork.query() | |
.subscribe(::displayResponse) | |
.disposeBy(onStop) | |
// Example 1 (Verbose) | |
DummyNetwork.query() | |
.subscribe(::displayResponse) | |
.disposeBy(lifecycle.disposers.onStop) | |
// Example 2 | |
onStop += DummyNetwork.query() | |
.subscribe(::displayResponse) | |
// Example 2 (Verbose) | |
lifecycle.disposers.onStop += DummyNetwork.query() | |
.subscribe(::displayResponse) | |
} | |
private fun displayResponse(response: String) { | |
textView.text = response | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment