title: Is it ok to use sharedPrefrence with Coroutine kotlin
body: <p>I have injected <code>sharedPreference</code> in <code>ViewModel</code>. </p>
  
  <blockquote>
    <p>Can I use android specific resource's while embedding Coroutine scope which automatically suspended when ViewModel loses scope.</p>
  </blockquote>
  
  <p>I mean is it ok to use preferende in ViewModel if we add a viewModel launch scope</p>
  
  <p><strong>A CoroutineScope keeps track of all coroutines it creates. Therefore, if you cancel a scope, you cancel all coroutines it created</strong></p>
  
  <pre><code>@ContributesViewModel
  class SplashViewModel @Inject constructor(private val prefs: PrefStore) : BaseViewModel() {
  
      val onMoveToNext = ClassLiveData()
  
      init {
          scope.launch {
              val activity = if(prefs.isLoggedIn()) HomeActivity::class
              else OnBoardingActivity::class
              onMoveToNext.postValue(activity)
          }
      }
  
      ///fun saveDeviceID(id:String) = prefs.setDeviceID(id)
      //fun createErrorCodeHash() ={}
  
      fun getIsLoggedIn():Boolean = prefs.isLoggedIn()
  
      fun setSecondTimeLogin(boolean: Boolean) = prefs.setIsSecondTimeLogin(boolean)
  }
  </code></pre>
  
  <p>Where </p>
  
  <pre><code>abstract class BaseViewModel: ViewModel() {
  
      private val job = Job()
      val scope = CoroutineScope(Dispatchers.IO + job)
  
      override fun onCleared() {
          super.onCleared()
          job.cancel()
      }
  
  }
  </code></pre>
  
  <p>where ClassLiveData</p>
  
  <pre><code>typealias ClassLiveData = MutableLiveData&lt;KClass&lt;*&gt;&gt;
  </code></pre>
  
  <p>And called it in SplashActivity </p>
  
  <pre><code>viewModel.onMoveToNext.listen(this) {
      Handler().postDelayed({
           val intent = Intent(this, it.java)
          intent.putExtra("Role", "LOGIN")
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
          startActivity(intent)
      }, 2000)
  </code></pre>