O
O
Oleksandr Shcherbak2020-02-17 14:16:50
Java
Oleksandr Shcherbak, 2020-02-17 14:16:50

How to save state on screen rotation?

There is text TextView nested in ScrollView. How to save the place where you stopped reading when you rotate the screen? According to the tutorial, you need to use: protected void onRestoreInstanceState(Bundle saveInstanceState); protected void onSaveInstanceState(Bundle saveInstanceState); But I do not understand what needs to be written in these methods.

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".old_unused.ActivityBox_1">

    <LinearLayout
        android:orientation="vertical"
        style="@style/RelativeBox">

        <TextView
            android:id="@+id/Ranishni"
            android:text="@string/This_1"
            style="@style/Size.text">
        </TextView>

    </LinearLayout>

</ScrollView>

5e4a75f809f76195359106.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Begemotishe, 2020-02-17
@Begemotishe

In your case, it will probably be enough to assign an id to the ScrollView using the android:id="name" property and the SDK will save the state automatically when rotated. That is, for example:

<ScrollView
    android:id="scroll_name"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".old_unused.ActivityBox_1">
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question