Android 无限动画集内存/进程问题

Android 无限动画集内存/进程问题,android,Android,我正在努力解决操作系统中的一个巨大缺陷。这就是我要做的 我在视图上有一个带有简单无限动画集动画的活动: <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially" > <objectAnimator android:durati

我正在努力解决操作系统中的一个巨大缺陷。这就是我要做的

我在视图上有一个带有简单无限动画集动画的活动:

<?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>

此动画基本上会按顺序淡入淡出视图。动画效果很好

在活动的onDestroy()方法中,我使用animation.end()结束动画

发生的情况是,即使活动被销毁,应用程序的进程仍然使用处理器时间:

这毫无意义,因为活动已关闭

我已经测试了一次又一次,移除AnimatorSet修复了这个问题

我还尝试了几种不同的方法来删除AnimatorSet:animation.end()、animation.cancel()、animation=null


你们觉得怎么样?

看来我用错了:

我所做的:

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();
    }
}
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();
    }
}
是什么解决了这个问题:

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();
    }
}
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();
    }
}