Hello everybody. In general, the essence of my problem.
I have a simple timer program: press the "Start" button - the timer ticks, click "Stop" - the timer stops. The timer is displayed in ЧЧ:ММ:СС format and works fine. But when I minimize the application and then deploy it again - the timer is all zeroes. I look at the logs - seconds, minutes and hours are ticking, that is, with the logic of the program everything is in order, I AsyncTask out the calculations in the AsyncTask stream. I came to the conclusion that the problem is in displaying the current time. How I do it:
Here is the markup of the xml file, seconds is tvsecond , minutes is tvminute , hours is tvhour

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/back4"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center" android:layout_weight="1" > <ImageButton android:contentDescription="@string/settings" android:id="@+id/btSettings" android:layout_width="40dp" android:layout_height="40dp" android:layout_gravity="top|right" android:onClick="onClickSet" android:background="@drawable/settings_icon" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_vertical" android:layout_gravity="center" android:layout_weight="3" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_horizontal|center_vertical" android:layout_gravity="center" android:layout_marginBottom="30dp" > <TextView android:id="@+id/tvhour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:textColor="@color/white_color" android:text="@string/hour" android:textSize="40sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="@string/twoPoint" android:textColor="@color/white_color" android:textSize="40sp" /> <TextView android:id="@+id/tvminute" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="@color/white_color" android:gravity="center" android:text="@string/minute" android:textSize="40sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:text="@string/twoPoint" android:textColor="@color/white_color" android:textSize="40sp" /> <TextView android:id="@+id/tvsecond" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textColor="@color/white_color" android:gravity="center" android:text="@string/second" android:textSize="40sp" /> </LinearLayout> <TextView android:id="@+id/timePeriod" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="30dp" android:gravity="center" android:textColor="@color/white_color" android:text="@string/timePeriod" android:textSize="25sp" /> <Button android:id="@+id/button1" android:layout_width="137dp" android:layout_height="wrap_content" android:layout_gravity="center" android:onClick="onClickGoStop" android:text="@string/start" /> <Button android:id="@+id/btType" android:layout_width="137dp" android:layout_height="wrap_content" android:layout_gravity="center" android:onClick="onClickType" android:text="@string/record" /> <Button android:id="@+id/btShow" android:layout_width="137dp" android:layout_height="wrap_content" android:layout_gravity="center" android:onClick="onClickShow" android:text="@string/show" /> </LinearLayout> </LinearLayout> В главном классе я создаю TextView: TextView secTextView, minTextView, hourTextView; hourTextView = (TextView)findViewById(R.id.tvhour); minTextView = (TextView)findViewById(R.id.tvminute); secTextView = (TextView)findViewById(R.id.tvsecond); 

Well, then in the AsyncTask stream, using the publishProgress() method, publishProgress() assign the seconds values ​​to the text fields. On Android 2.3 everything works, on 4.0.4, when the application is minimized / expanded, the timer is reset to zero.
I deduce the values ​​of hourTextView, minTextView и secTextView into logs - everything is displayed correctly, why are tvhour, tvminute and tvsecond displayed incorrectly?
Tell me, please, what could be the error and where to dig? Maybe this is a confusion of some of the versions?

Thank.

    1 answer 1

    Most likely you did not specify in the AndroidManifest.xml file for activation configChanges = "screenSize"

    And AsyncTask works because it works in a separate thread and does not depend on the restart of the activation

    UPDATE:

    Then I advise you to read this article here. Yes, it says about the rotation of the screen. Yes, you do not rotate the screen, but minimize / unfold the application. BUT - the connection with TASK is lost, how to save it is written in the article.

    • There was no talk about AsyncTask - I already found out that the problem is not in it. Your method did not work. - svyat_kimata
    • updated the answer - Roman Zakharov