class Success<T>(val data: T) : Status<T>() data class Failure(val throwable: Throwable) : Status<Nothing>() } Loading(௨৴த) Failure(ࣦഊ) Success(ޭ) Status
class MainActivity : AppCompatActivity() { private val mainViewModel: MainViewModel by viewModel() private val someViewModel: SomeViewModel by viewModel() // ... (KOINͰDI͢Δྫ)
String ) data class MainItem( val id: String, val title: String? ) ྫ͑.. ItemΫϥεͷ title ϓϩύςΟ API ͷ݁ՌΛ֨ೲ͍ͯ͠ Δ߹্ɺۭจࣈྻ ۭനจࣈྻ ؚ͕·Εͯ͠·͏ ϝΠϯը໘ͰͦΕΒແޮͳσʔλ(= null)ͱͯ͠ѻ͍ ͍ͨ ͱ͍͏έʔε title = "" title = " " ม
@MainThread override fun observe(owner: LifecycleOwner, observer: Observer<in T>) { if (hasActiveObservers()) { Log.w("SingleLiveEvent", "Multiple observers registered" + " but only one will be notified of changes.") } super.observe(owner, Observer { if (pending.compareAndSet(true, false)) { observer.onChanged(it) } }) } @MainThread public override fun setValue(value: T?) { pending.set(true) super.setValue(value) } } https://github.com/googlesamples/android-architecture/blob/dev-todo-mvvm-live/todoapp/app/ src/main/java/com/example/android/architecture/blueprints/todoapp/SingleLiveEvent.java Λࢀߟʹ͠·ͨ͠