Category : kotlin-coroutines

I have three fragments on an activity. On one I am loading a default view which is to be populated by data from Google Calendar but asynchronously -syncwholeCalendar(). While the app has loaded the default view, the app crashes when, Calendar data is being loaded and the user is on another fragment in the activity ..

Read more

I have written a new usecase to communicate to api which uses Flow, I am guessing I am not handing the threading properly in the Usecase between Main thread and IO thread, This is the error I get -01-18 02:20:40.555 26602-26870/com.xxx.xx.staging E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-4 Process: com.xxx.xx.staging, PID: 26602 java.lang.IllegalStateException: Event bus [Bus "fill_order"] accessed ..

Read more

I want to retrieve data from Datasource. But turns out it didnt get executed at all. How can i solve it? here is my code Repository.kt // all logcat in repository is executed override fun getDetailGame(id: Int): Flow<Resource<Game>> { Log.d("Repo", "getDetailGame: called") return flow { Log.d("Repo", "getDetailGame: before flow") remoteDataSource.getDetailGame(id) Log.d("Repo", "getDetailGame: after flow") } ..

Read more

MainActivity.kt code val r = Retrofit.Builder() .baseUrl("https://reqres.in/api/") .addConverterFactory(GsonConverterFactory.create()) .build() val api = r.create(ResqResAPI::class.java) GlobalScope.launch(Dispatchers.IO) { try { val response = api.getUsers() GlobalScope.launch(Dispatchers.Main) { Toast.makeText( [email protected], "Request Success", Toast.LENGTH_SHORT ).show() } response.body()?.users?.let { printUsers(it) } } catch (e: Exception) { GlobalScope.launch(Dispatchers.Main){ Toast.makeText( [email protected], "Request Failed", Toast.LENGTH_SHORT ).show() } } } } private fun printUsers(users: List<UserResponse.User>) { ..

Read more

I’m writing some unit tests for my defined LocalDataSource classes that wraps the functionality of a Room databse DAO, my code looks like this: Room DAO Interface @Dao interface PersonDao { @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(person: Person) } LocalDataSource Class class PersonLocalDataSourceImpl(private val personDao: PersonDao) { suspend fun insert(dispatcher: CoroutineDispatcher, person: Person) = withContext(dispatcher) ..

Read more

As told in the title i try to create a recyclerview on fragment open with a variable. Here is a working version without variable: Fragment: viewModel.lists.observe(viewLifecycleOwner) { listAdapter.submitList(it) } ViewHolder: val lists = shishaDao.getList(HARDCODED_INT).asLiveData() As you can see, there is an hardcoded integer. This integer can hold different values, which is changing the lists value. ..

Read more

I’m studing coroutines but every times I don’t know how convert a java async architecture to a kotlin coroutines async architecture. For example, there are different library which use the java executors inside of they. For instance Firebase to write the log on file uses an executor instantiated inside of the crashlytics library. Which is ..

Read more

I’m trying to grab the frame from the video file using MediaMetadataRetriever with multiple parallel coroutine jobs, but the process takes more time comparing with running it with one coroutine. I don’t understand what is the problem, maybe MediaMetadataRetriever doesn’t work for parallel execution and it blocks getFrameAtIndex method invocation for the same file? or ..

Read more