I checked and found that collects have been increased two times by each click . I don't know what is the cause and what is the remedy for below code . I am a beginner in Android dev and this issue becomes a headache for me.
binding.downloadBtn.setOnClickListener {
var count = 0
if (id != null) {
viewModel.getDownloads(id)
}
lifecycleScope.launch {
viewModel.getDownloads.collect {
count++
Log.i("torrent movies", "count ${count} and download ${it}")
if (downloads!=null) {
bundle.putParcelable(Constants.DOWNLOADS, downloads)
findNavController()
.navigate(R.id.action_movieDetailsFragment_to_downloadFragment, bundle)
}
}
}
}