Я создал довольно сложную анимацию конца в приложении с открытым исходным кодом.MemoryLeak in onBackPressed with Animation
Если метод 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() .. использование отделка() сверху анимация конец –
oh извините. полностью пропустил эту линию. была одной из вещей, которые я пробовал. подождите, я обновляю свой вопрос. – mikepenz