What's the proper way to use Coroutines in Activity?

Ranjithkumar

For viewModels we can use

 viewModelScope.launch {
     //long running operation
 }

this is the proper way for viewModel.

Same like this, what's the best way to launch coroutines in Activity?

I used GlobalScope launch in Activity, is it right approach?

GlobalScope.launch {

}
Ivo Beckers

For activities you should use lifecycleScope

Read more about it in the official documentation:

Use Kotlin coroutines with lifecycle-aware components

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What is the proper way to cancel coroutines with common mutex

In BeautifulSoup, what's the proper way to use a strainer with lxml parsing?

What is the proper way to use JQuery’s .load() on an image?

What is the proper way to use inotify?

What is the proper way to use continue?

What is the proper way to use if _ is _ or .isKind(of: )

What is the proper way to use IF THEN in AQL?

What is the proper way to use @property in python

what is the "proper" way to use django REST framework?

What is the proper way to use a .equals method in Java?

What is the proper way to use an alternative binary

What is the proper way to use multiple layouts in ReactJS

What is the proper way to use bit array in Rust?

What is the proper way to use Toolbar and SwipeRefreshLayout?

What is the proper way to use React Memo with Flow?

what is the proper way to use $nin operator with mongoDB

What is the proper/right way to use Async Storage?

What is a Proper way to use Input range listener

What is the proper way to use codecs' encoding in Python?

What is the proper way to use Python mock's autospec for objects's methods?

What is the proper way to handle subscriptions in RxJava/RxAndroid for an Activity Lifecycle?

What is the proper way to send a broadcast from an activity to a service?

What's the proper way to setup an Android PreferenceFragment?

What's the proper way to share the interface?

What's the proper way to check if a constant is defined?

What's the proper way to document callbacks with jsdoc?

What's the proper way of passing a ref to a prop?

What's the proper way to propagate .catch in promise?

What's the proper way to recurse in LLVM assembly?