Udit003
12/30/2018, 7:41 AMreplaces
Fragments. I have created global instances of fragments in the activity (in order not to re-instantiate the fragments again on tab change).
Now once a fragment is loaded and replaced (on tab change),its complete lifecycle is called (from onAttach()
to onDestroy()
and onDetach()
). So I expected the viewmodel of the fragment to also get destroyed and onCleared()
called once the onDestroy()
of the fragment is called. Also new viewmodel should be instantiated when fragments is created again.
But it is not happening as expected. The viewmodel is only created once and onCleared()
is only called the first time onDestroy()
of the fragment is called. I tested it using the following code :
class HomeViewModel : ViewModel() {
init {
Log.d("Fragment_Checker","Viewmodel_INIT")
}
private var counter = 1
fun getCounter():Int{
counter++
return counter
}
override fun onCleared() {
Log.d("Fragment_Checker","ViewModel_Destroyed")
super.onCleared()
}
}
/*Fragment class */
class HomeFragment : androidx.fragment.app.Fragment() {
val viewModel: HomeViewModel by viewModel()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Fragment_Checker","onCreate")
}
override fun onResume() {
super.onResume()
Log.d("Fragment_Checker","Counter "+viewModel.getCounter())
}
override fun onDetach() {
super.onDetach()
Log.d("Fragment_Checker","onDetach")
}
override fun onDestroy() {
super.onDestroy()
Log.d("Fragment_Checker","onDestroy")
}
The log output looks like :
onCreate
Viewmodel_INIT
Counter 2
//tab changed
ViewModel_Destroyed
onDestroy
onDetach
//move back to home tab
onCreate
Counter 3
//tab changed
onDestroy
onDetachpoohbar
12/31/2018, 2:01 PMkoin-ktor
package? What does it add over koin-core
?amatkivskiy
01/02/2019, 11:45 AMViewModel
can have another ViewModel as constructor dependency ?
Something like this
viewModel { BasketViewModel(get()) }
viewModel { SelectProductViewModell(get(), basketViewModel) }
nwh
01/04/2019, 9:33 PMonCreated
of my Activity right now, and it errors due to re-declaration of singlesPavel.AZ
01/06/2019, 12:30 PMgmariotti
01/07/2019, 12:15 PMciriti
01/07/2019, 5:49 PMgaspard
01/14/2019, 9:35 PMarnaud.giuliani
01/25/2019, 2:51 PMsmassive
01/31/2019, 10:33 AMgumil
02/04/2019, 10:52 AMVinicius Carvalho
02/04/2019, 3:39 PMbastienC
02/06/2019, 12:34 PMsingle<BaseCmsMapper<OnClickHodor?, OnClick>>(name = "onClickMapper") {
OnClickMapper(errorDispatcher = get(), templateMapper = get("templateMapper"))
}
onClickMapper dependency is used just below like :
single<BaseCmsMapper<SeasonHodor, Season>>(name = "seasonMapper") {
SeasonMapper(errorDispatcher = get(), onClickMapper = get("onClickMapper"))
}
returned error is : 2019-02-06 12:26:02.392 18700-18700/? E/KOIN: [ERROR] - Error while resolving instance for class 'com.canal.android.mycanalpoc.cms.common.BaseCmsMapper' - error: org.koin.error.NoBeanDefFoundException: No compatible definition found. Check your module definition
2019-02-06 12:26:02.395 18700-18700/? E/KOIN: [ERROR] - Error while resolving instance for class 'com.canal.android.mycanalpoc.cms.common.BaseCmsMapper' - error: org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='onClickMapper',class='com.canal.android.mycanalpoc.cms.common.BaseCmsMapper']' due to error :No compatible definition found. Check your module definition
Any idea?arnaud.giuliani
02/06/2019, 1:38 PMAlan Evans
02/06/2019, 1:55 PMpeterG
02/07/2019, 8:13 AMkenkyee
02/11/2019, 9:29 PMarnaud.giuliani
02/18/2019, 7:54 AMgergo
02/18/2019, 2:26 PMMaikals
02/20/2019, 7:39 AMAlex
02/21/2019, 11:42 AMclass ModulesTest : KoinTest {
@Test
fun checkAllModules() {
koinApplication { modules(listOf(coreModule, appModule, roomModule, moshiModule)) }.checkModules()
}
}
but I am getting the following error: org.koin.core.error.NoBeanDefFoundException: No definition found for 'android.content.Context' has been found
I know it is because my room module is using androidApplication()
but I don't know how to fix it. Any ideas please??Alex
02/21/2019, 11:45 AMorogersilva
02/21/2019, 6:30 PMarnaud.giuliani
02/26/2019, 8:34 AMkenkyee
02/28/2019, 9:46 PMkenkyee
03/04/2019, 6:46 PMSergio Crespo Toubes
03/06/2019, 11:43 AMEXTRA_TASK_ID
with koin?arnaud.giuliani
03/13/2019, 3:12 PMVinicius Carvalho
03/13/2019, 5:24 PMnwh
03/13/2019, 7:03 PMnwh
03/13/2019, 7:03 PMarnaud.giuliani
03/13/2019, 8:52 PMdeclareMock
function in koin-test?nwh
03/13/2019, 8:54 PM