I'm looking for a list of movies in an API, the project is in MVVM and the search is being done perfectly. However, when opening the app, the user has to exit and open it again for the list to display the results. How to solve this?
In onStart I use Observe
override fun onStart() {
super.onStart()
Log.d("TESTE", "onStart")
viewModel.movieList.observe(this, Observer {
Log.d("TAG", "onCreate: $it")
for (i in it.results){
list.add(i)
}
if (page < 66){
page ++
}
})
In onResume
override fun onResume() {
super.onResume()
val scope = MainScope()
adapter.setDataSet(list)
scope.launch {
viewModel.getAllMovies(page)
viewModel.getAllGenre()
}
val recyclerView : RecyclerView = findViewById(R.id.recycler_vie_movie_list)
val layoutManager = GridLayoutManager(applicationContext, 3, GridLayoutManager.VERTICAL, false)
recyclerView.layoutManager = layoutManager
recyclerView.adapter = adapter