This question already has an answer here:
I am building a simple timer app in which I am using android chronometer to track time passed. but when I start chronometer and change orientation to landscape the chronometer resets and and show 00:00 again. I want it to retain its value.
layouts for portrait
and landscape
are different
portrait--> Layout
folder
landscape->layout_land
folder
<Chronometer
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/chronometer1"
android:layout_above="@+id/button2"
android:textStyle="bold"
android:textColor="@color/Indigo"
android:text="Chronometer"
android:layout_toLeftOf="@+id/save_btn"
android:typeface="serif"
android:textSize="40dp"/>
Here is what the doc said :
Recreating an Activity
If you need to Save activity's state before changing orientation, you have to override
onSaveInstanceState()
. This method will help you save all the values you want to get back after orientation changes. Then restore them inonCreate()
method.Here is an exemple :
Now retrieve it when creating the activity :