Trieu Tran
03/17/2021, 8:36 AMChris
03/17/2021, 11:18 PMAnshulupadhyay03
03/18/2021, 9:43 AMSeuan Rahman
03/18/2021, 10:47 AMMarko Novakovic
03/18/2021, 1:49 PMclass OnActiveTriggerLiveData<T>(
private val doOnActive: MutableLiveData<T>.() -> Unit
) : MutableLiveData<T>() {
override fun onActive() {
super.onActive()
doOnActive()
}
}
and you have instance of this inside your ViewModel
like so:
class AccountViewModel(val repo: Repo) : ViewModel() {
private val _account = OnActiveTriggerLiveData<Account> { value = repo.account }
val account: LiveData<Account>
get() = _account
So every time view(Activity/Fragment) hits onStart
account will be updated with the newest value so you don’t have to expose method from ViewModel
and call it from onStart
nor onResume
You just observe LiveData
and not care about anything elseRagvax
03/18/2021, 1:55 PMluke_c
03/18/2021, 5:12 PMErnestas
03/18/2021, 6:31 PMKevin Janvier Chinabalire
03/18/2021, 7:22 PMdatastore
i have tried this
val getUsers: Flow<User?>
get() = dataStore.data.map { preference ->
preference[USER_DETAILS]
}
for retrieving
and for saving
dataStore.edit {
it[USER_DETAILS] = MyObject
}
but nothing is working …Kevin Janvier Chinabalire
03/18/2021, 7:35 PMtruongpham_se
03/19/2021, 3:20 AMParth Gupta
03/19/2021, 6:30 AMAnshumaan Kumar Prasad
03/19/2021, 9:50 AMSeuan Rahman
03/19/2021, 12:36 PMFelix Thomas
03/19/2021, 12:39 PM<http://android.net|android.net>.conn.CONNECTIVITY_CHANGE
intent, however that’s been deprecated. Anyone got any good ideas on how to implement this on devices running Android N or over?Lena Brusilovski
03/19/2021, 6:00 PMArun
03/19/2021, 7:59 PM..preferences_pb.tmp could not be renamed to....preferences_pb
. It’s exactly as in https://stackoverflow.com/questions/66446999/could-not-be-renamed-to-data-user-0-app-android-githubservice-files-datastore-m. Has anyone come across such issue?David Martin
03/20/2021, 5:35 AMval fragmentTransaction = fragmentManager!!.beginTransaction()
Before I'm was able to navigate between fragments using above code but today isn't, how on the Earth has a bug like this?
Then I changed my code to using childFragmentManager and parentFragmentManager but nothing happen, there is no logcat, no error, just can't navigate between fragments anymore, I've debuged and every variables aren't null.
Is there anyone facing this bug? any solution works around? thanks in advance!Slackbot
03/20/2021, 5:15 PMtherealbluepandabear
03/20/2021, 8:47 PMDhanya S Pillai
03/21/2021, 9:51 AM1.4.21
Android studio : 4.1.2
Note: Im not using jetpack composeSteve
03/22/2021, 10:24 PMTony Kazanjian
03/23/2021, 1:26 AMandroidx.test.annotation.UiThreadTest
? I currently have androidTestImplementation 'androidx.test:annotations:1.3.0'
in my module's build.gradle file, but I cannot find the needed annotation.
Edit: Nevermind, SO to the rescue: 'androidx.test:rules:1.3.0'
I guess a follow-up question would be, how the hell would I have found that out otherwise? The documentation points me to the annotations package. Why wouldn't this annotation be there?Abdalla Hassanin
03/23/2021, 1:16 PMHossein Amini
03/23/2021, 5:37 PMLilly
03/24/2021, 12:12 PMsealed class Foo {
abstract fun bar()
}
class A : Foo()
class B : Foo()
/* in another file */
fun A.bar() {
// implementation
}
It seems it's not possible but maybe there is something similar? I just want to move the implementation of bar()
to other files because the LOC for the implementation is huge. I want to avoid a file with thousands of LOC. Any ideas?Dustin Lam
03/24/2021, 7:35 PMScott Kruse
03/24/2021, 10:37 PMMateusz Holak
03/25/2021, 8:32 AMjean
03/25/2021, 9:13 AMval state: StateFlow<MyViewState> = myFlow
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), MyViewState())
does one stills need to use something like this from a view
lifecycleOwner.addRepeatingJob(Lifecycle.State.STARTED) {
viewModel.state.collect {
// do something with the data
}
}
i’m not completely sure what SharingStarted.WhileSubscribed()
implies regarding android and its life cyclejean
03/25/2021, 9:13 AMval state: StateFlow<MyViewState> = myFlow
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), MyViewState())
does one stills need to use something like this from a view
lifecycleOwner.addRepeatingJob(Lifecycle.State.STARTED) {
viewModel.state.collect {
// do something with the data
}
}
i’m not completely sure what SharingStarted.WhileSubscribed()
implies regarding android and its life cycleManuel Vivo
03/25/2021, 9:25 AMmyFlow
is or how it’s implemented.
WhileSubscribed()
means that when there are no collectors available, the underlying flow will be cancelled.WhileSubscribed
to Eagerly
or Lazily
jean
03/25/2021, 9:29 AMRemy Benza
03/26/2021, 8:35 AM