Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
- ...
- GlobalScope.launch(Dispatchers.Main) {
- val job = GlobalScope.launch(Dispatchers.IO) {
- val task = async(Dispatchers.IO) {
- settingsInteractor.getStationSearchCountry().let {
- countryName = it.name
- }
- settingsInteractor.getStationSearchRegion().let {
- regionName = it.name
- }
- }
- task.await()
- }
- job.join()
- }
- }
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- country.updateCaption(countryName)
- region.updateCaption(regionName)
- }
- private var job: Job = Job()
- override val coroutineContext: CoroutineContext
- get() = Dispatchers.Main + job
- @Override
- public void onDestroy() {
- super.onDestroy();
- job.cancel()
- }
- implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- launch {
- val operation = async(Dispatchers.IO) {
- settingsInteractor.getStationSearchCountry().let {
- countryName = it.name
- }
- settingsInteractor.getStationSearchRegion().let {
- regionName = it.name
- }
- }
- operation.await() // wait for result of I/O operation without blocking the main thread
- // update views
- country.updateCaption(countryName)
- region.updateCaption(regionName)
- }
- }
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- GlobalScope.launch(Dispatchers.IO) {
- settingsInteractor.getStationSearchCountry().let {
- countryName = it.name
- }
- settingsInteractor.getStationSearchRegion().let {
- regionName = it.name
- }
- launch(Dispatchers.Main) {
- country.updateCaption(countryName)
- region.updateCaption(regionName)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement