[SOLVED] How to cancel progress bar of Main Activity when moving to a Fragment?

Issue

I show a spinning progress bar before beginning a fragment. The run debugger shows that it is still running after the fragment is running and functioning.

Is there a proper way to end it? I simply want the user to know that something is happening while they wait (network connections, etc).

To expand a bit, the run monitoring of the emulator shows many lines like

D/eglCodecCommon: setVertexArrayObject

and these don’t occur if I comment out the View.VISIBLE line of code

EDITED to note that those messages only appear in the run log if banner ads are enabled. I would assume that the bar is still spinning in either case, but just not flagged.

        binding.slowButton.setOnClickListener() {
            binding.pBar.visibility = View.VISIBLE
            binding.mainActFields.visibility = View.GONE
            supportFragmentManager.beginTransaction().replace(R.id.MainFragment,MainFragment()).commit()
            Log.i(MAIN_ACTIVITY_TAG, "Clicked")
        }



    <ProgressBar
        android:id="@+id/pBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:progressTint="@color/white"
        android:foregroundTint="@color/white"
        android:visibility="gone"
        android:elevation="500dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />```

Solution

I assume pBar is an Indeterminate Progress , you’re gonna need to call:

binding.pBar.visibility = View.GONE

to stop it.

What you need to do is delay close pBar (possibly using coroutines), but i think in this scenario using a ProgressBar when displaying your fragment is unnecessary unless pBar is from another fragment.

In the case of the log below,

D/eglCodecCommon: setVertexArrayObject

i think the ad banner is having a beef with pBar since it is visible and running indefinitely.

Answered By – Rigo Regalado

Answer Checked By – Cary Denson (BugsFixing Admin)

Leave a Reply

Your email address will not be published.