简体   繁体   English

为什么动画在屏幕上重新启动然后又关闭又打开?

[英]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. 动画是通过startAnimation()方法在onCreate启动的。 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? 由于应用程序处于仅横向模式且Android屏幕处于关闭状态,因此这会导致动画重新启动吗?

I haven't found such cases on the net. 我尚未在网上找到此类案例。

Turning screen OFF and then ON indeed restarts the Activity . 关闭屏幕然后再打开屏幕确实会重新启动Activity

So anyone facing the same problems, just add the usual attribute into the Manifest file next to the Activity where the animations occur. 因此,面对同样问题的任何人,只需将通常的属性添加到动画发生的Activity旁边的Manifest文件中即可。

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. 检查所有这些的一种简单方法是将Log放入所有onCreateonResume ,...方法中。 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. 无论如何,从“肖像”转移到“风景”(或从“风景”转移到“肖像”)并关闭然后再打开屏幕可能会重新启动活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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