首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无限AnimatorSet内存/进程问题

无限AnimatorSet内存/进程问题
EN

Stack Overflow用户
提问于 2013-11-11 17:54:35
回答 1查看 965关注 0票数 0

我正在与我认为是一个巨大的错误在这里的操作系统。这就是我想要做的。

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

代码语言:javascript
复制
<?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()、动画= null

你们觉得怎么样?

EN

回答 1

Stack Overflow用户

发布于 2013-11-11 18:16:14

好像我用错了:

我所做的:

代码语言:javascript
复制
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();
    }
}

修复了这个:

代码语言:javascript
复制
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();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19912736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档