java – Prevent Reload WebView onResume()-ThrowExceptions

Exception or error:

After lock my screen and unlock pressing the turn off button my webview is reloaded.
I have found that problem is with onResume()

@Override
protected void onResume() {
    super.onResume();
     mWebView.onResume();
     mWebView.resumeTimers();
}

Reload is happen only with webview, as i can see navigation bar at the bottom is untouched. So how to prevent reloading webview also i will need onResume() for future use so removing is not solution.
Here is Activity layout

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    android:windowTranslucentNavigation="false"
    tools:context=".MainActivity">


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefresh"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:overScrollMode="never"
        android:soundEffectsEnabled="true"
        app:layout_constrainedHeight="true"
        app:layout_constrainedWidth="true"
        app:layout_constraintBottom_toTopOf="@id/BottomLayout"
        app:layout_constraintEnd_toEndOf="@id/BottomLayout"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:scrollbars="none"
            android:visibility="gone" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <include
        android:id="@+id/netCon"
        layout="@layout/network_connection" />

    <include
        android:id="@+id/srvCon"
        layout="@layout/server_connection" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/BottomLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:animateLayoutChanges="true"
            android:background="@drawable/border_top_bottom_menu"
            android:clipToPadding="false"
            android:duplicateParentState="false"
            android:fitsSystemWindows="false"
            android:focusableInTouchMode="false"
            android:theme="@style/bottom_navigation_menu"
            android:visibility="visible"
            app:barrierAllowsGoneWidgets="true"
            app:itemHorizontalTranslationEnabled="false"
            app:itemIconSize="22dp"
            app:itemIconTint="@color/drawer_item"
            app:itemTextColor="@color/drawer_item"
            app:labelVisibilityMode="labeled"
            app:layout_constraintBottom_toTopOf="@id/Notification"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:menu="@menu/bottom_navigation_menu">

        </com.google.android.material.bottomnavigation.BottomNavigationView>

        <LinearLayout
            android:id="@+id/Notification"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:background="@color/notification_offline"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical"
            android:weightSum="1"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent">

            <TextView
                android:id="@+id/notificationText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/roboto"
                android:textAlignment="center"
                android:textColor="#FFFFFF"
                android:textSize="12sp"
                android:textStyle="normal" />
        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

    <ProgressBar
        android:id="@+id/progressbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_gravity="center|center_vertical"
        android:indeterminate="false"
        android:theme="@style/progressWhite"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *