【发布时间】:2015-04-15 09:42:59
【问题描述】:
我在一个开源应用程序中创建了一个相当复杂的结束动画。
如果调用 onBackPressed() 方法,应用程序将为视图设置动画并关闭。似乎有一个内存韭菜,因为它不会停止分配新的内存。如果我删除动画并只调用正常的 onBackPressed 我没有提到的行为。
这是我在 onBackPressed 方法中调用的代码:
//make global var :D
ViewPropertyAnimator hideFabAnimator;
@Override
public void onBackPressed() {
mFabDownloadButton.animate()
.translationX(0)
.setDuration(ANIMATION_DURATION_MEDIUM)
.start();
//move the share fab below the normal fab (58 because this is the margin top + the half
mFabShareButton.animate()
.translationX(0)
.setDuration(ANIMATION_DURATION_MEDIUM)
.setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
//create the fab animation and hide fabProgress animation, set an delay so those will hide after the shareFab is below the main fab
hideFabAnimator = Utils.hideViewByScaleXY(mFabButton)
.setDuration(ANIMATION_DURATION_MEDIUM);
Utils.hideViewByScaleXY(mFabDownloadButton)
.setDuration(ANIMATION_DURATION_MEDIUM)
.start();
Utils.hideViewByScaleXY(mFabShareButton)
.setDuration(ANIMATION_DURATION_MEDIUM)
.start();
Utils.hideViewByScaleXY(mFabProgress)
.setDuration(ANIMATION_DURATION_MEDIUM)
.start();
//add listener so we can react after the animation is finished
hideFabAnimator.setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
try {
ViewPropertyAnimator hideFabAnimator = Utils.hideViewByScaleY(mTitleContainer);
hideFabAnimator.setListener(new CustomAnimatorListener() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
coolBack()
}
});
} catch (Exception ex) {
super.onAnimationEnd(animation);
coolBack()
}
}
});
hideFabAnimator.start();
super.onAnimationEnd(animation);
}
})
.start();
}
/**
*
*/
private void coolBack() {
try {
super.onBackPressed();
} catch (Exception e) {
}
}
你可以在这里找到相同的来源@github:https://github.com/mikepenz/wall-splash-android/blob/master/app/src/main/java/com/mikepenz/unsplash/activities/DetailActivity.java#L701
我已经尝试了很多不同的东西。但没有任何帮助。
谢谢。
【问题讨论】:
-
尝试删除 super.onBackPressed().. 在动画结束时使用 finish()
-
对不起。确实完全错过了这条线。是我尝试过的事情之一。等我更新我的问题。
标签: android performance android-activity memory-leaks out-of-memory