[英]Infinite AnimatorSet memory/process issue
I am struggling with what I think is a huge bug in the OS here. 我正在为我认为这是操作系统中的一个巨大错误而苦苦挣扎。 Here's what I'm trying to do.
这就是我想要做的。
I have an activity with a simple infinite AnimatorSet animation on a view : 我在一个视图上有一个简单的无限AnimatorSet动画的活动:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially" >
<objectAnimator
android:duration="1000"
android:propertyName="alpha"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:valueFrom="0.3"
android:valueTo="1.0" />
</set>
This animation basically fades the view in and out sequentially . 该动画基本上使视图顺次淡入和淡出 。 The animation works.
动画有效。
In the activity's onDestroy() method, I end the animation using animation.end(). 在活动的onDestroy()方法中,我使用animation.end()结束动画。
What happens is, even when the activity is destroyed, the app's process still uses processor time : 发生的事情是, 即使活动被破坏,应用程序的进程仍会使用处理器时间 :
This makes no sense, as the activity is closed. 这是没有意义的,因为该活动已关闭。
I have tested this again and again, and removing the AnimatorSet fixes that. 我已经对此进行了一次又一次的测试,并删除了AnimatorSet对此进行了修复。
I have also tried several different methods for removing the AnimatorSet : animation.end(), animation.cancel(), animation = null 我还尝试了几种不同的方法来删除AnimatorSet:animation.end(),animation.cancel(),animation = null
What do you guys think ? 你们有什么感想 ?
It seems I was using this wrong : 看来我在用这个错:
What I did : 我做了什么 :
onCreate(){
animation = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.animation);
animation.setTarget(myView);
animation.start();
}
onDestroy(){
if(animation != null){
animation.cancel();
}
}
onPause(){
if(animation != null){
animation.end();
}
}
onResume(){
if(animation != null){
animation.start();
}
}
What fixed this : 解决此问题的方法:
onCreate(){
animation = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.animation);
animation.setTarget(myView);
animation.start();
}
onDestroy(){
if(animation != null){
animation.cancel();
}
}
onPause(){
if(animation != null && animation.isStarted()){
animation.end();
}
}
onResume(){
if(animation != null && !animation.isStarted()){
animation.start();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.