简体   繁体   中英

Why animation restarts on screen going off then on?

I am using a landscape-only app. There is an activity and animation. Animation is started in onCreate via startAnimation() method. So nothing unusual and nothing unordinary.

When animation ends, I turn screen off and then on, and the animations restarts !

Why is this happening and how to prevent this?

Since the app in in landscape only mode and Android screen off is in portrait, is this causing animation restart?

I haven't found such cases on the net.

Turning screen OFF and then ON indeed restarts the Activity .

So anyone facing the same problems, just add the usual attribute into the Manifest file next to the Activity where the animations occur.

Like this:

<activity android:name=".MyActivity" 
          android:configChanges="orientation|keyboardHidden" /> 

A simple way to check all this is to put Log in all onCreate , onResume , ... methods. Then, you should be able to see which methods are called during your tests.

Anyway, passing from Portrait to Landscape (or from Landscape to Portrait) and turning your screen off and on will probably restart the activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM