I use this example to generate pdf file from recyclerview. I call the getScreenshotFromRecyclerView function inside doInBackground of an AsyncTask and the bitmap is generated successfully.
The problem is if I added a CircularProgressIndicator inside recyclelerview's listitem, it throws AndroidRuntimeException.
Caused by: android.util.AndroidRuntimeException: Animators may only be run on Looper threads
at android.animation.ValueAnimator.end(ValueAnimator.java:1204)
at com.google.android.material.progressindicator.DrawableWithAnimatedVisibilityChange.endAnimatorsWithoutCallbacks(DrawableWithAnimatedVisibilityChange.java:322)
It is because this line in getScreenshotFromRecyclerView:
RecyclerView.ViewHolder holder = adapter.createViewHolder(view, adapter.getItemViewType(i));
Which cause LayoutInflater to createView, in thread which isn't UI thread.
I don't want to display the CircularProgressIndicator in the pdf (bitmap). Although I set its visibility to invisible/gone but it doesn't help. How to bypass the CircularProgressIndicator when creating the bitmap?
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="false"
android:visibility="invisible"
app:indicatorSize="120dp"
app:trackThickness="14dp" />