1

I can set the updated progress value into progressbar and textview value inside the progressbar at first time. But after i left current activity and come back to that activity again. It become with its default value which are specified at xml as follows

        <ProgressBar
    android:id="@+id/batteryLevel"
    android:layout_width="45dp"
    android:layout_height="20dp"
    android:layout_marginEnd="16dp"
    android:progressDrawable="@drawable/battery_level"
    android:max="100"
    style="@style/Widget.AppCompat.ProgressBar.Horizontal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@id/devName"/>

<TextView
    android:id="@+id/batteryLevelTv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OFF"
    android:textColor="#fff"
    app:layout_constraintTop_toTopOf="@id/batteryLevel"
    app:layout_constraintBottom_toBottomOf="@id/batteryLevel"
    app:layout_constraintStart_toStartOf="@id/batteryLevel"
    app:layout_constraintEnd_toEndOf="@id/batteryLevel"/>
            String battProgress = progress + "%";
            batteryTv.setText(battProgress);
            batteryTv.invalidate();
            batteryTv.requestLayout();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                batteryLevel.setProgress(progress, true);
            } else {
                batteryLevel.setProgress(progress);
            }

I use android api level 28. Can anyone helps me with this issue?

Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29
amart
  • 13
  • 3

1 Answers1

0

This looks to be an issue due to Activity Lifecycle.
If I assume correct It is happening due to any one of the following:
1) You are setting the progress data in onResume which is getting called again when the second Activity has finished and you navigate back.
2) You are recreating the Progress activity from Activity 2 After you exit, Instead of just passing updated data.

Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
  • yes it is correct due to activity lifecycle. It was fixed by changing progressbar and textview var as static. reference https://stackoverflow.com/questions/12433583/textview-stops-updating-after-bringing-activity-back-to-the-front – amart Nov 13 '19 at 07:28