Activity Transitions: Fix memory leak.
Bug 15731459 Change-Id: Id357d841a0db832e2525b7bbd75c8d8ccdb757d1
This commit is contained in:
@@ -191,7 +191,7 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
|
||||
*/
|
||||
public static final int MSG_SEND_SHARED_ELEMENT_DESTINATION = 108;
|
||||
|
||||
final private Window mWindow;
|
||||
private Window mWindow;
|
||||
final protected ArrayList<String> mAllSharedElementNames;
|
||||
final protected ArrayList<View> mSharedElements = new ArrayList<View>();
|
||||
final protected ArrayList<String> mSharedElementNames = new ArrayList<String>();
|
||||
@@ -507,6 +507,17 @@ abstract class ActivityTransitionCoordinator extends ResultReceiver {
|
||||
return bundle;
|
||||
}
|
||||
|
||||
protected void clearState() {
|
||||
// Clear the state so that we can't hold any references accidentally and leak memory.
|
||||
mWindow = null;
|
||||
mAllSharedElementNames.clear();
|
||||
mSharedElements.clear();
|
||||
mSharedElementNames.clear();
|
||||
mTransitioningViews.clear();
|
||||
mResultReceiver = null;
|
||||
mPendingTransition = null;
|
||||
}
|
||||
|
||||
protected long getFadeDuration() {
|
||||
return getWindow().getTransitionBackgroundFadeDuration();
|
||||
}
|
||||
|
||||
@@ -215,6 +215,17 @@ class ActivityTransitionState {
|
||||
restoreExitedViews();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
mEnteringNames = null;
|
||||
mExitingFrom = null;
|
||||
mExitingTo = null;
|
||||
mExitingToView = null;
|
||||
mCalledExitCoordinator = null;
|
||||
mEnterTransitionCoordinator = null;
|
||||
mEnterActivityOptions = null;
|
||||
mExitTransitionCoordinators = null;
|
||||
}
|
||||
|
||||
private void restoreExitedViews() {
|
||||
if (mCalledExitCoordinator != null) {
|
||||
mCalledExitCoordinator.resetViews();
|
||||
|
||||
@@ -134,6 +134,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
|
||||
transition.addListener(new Transition.TransitionListenerAdapter() {
|
||||
@Override
|
||||
public void onTransitionEnd(Transition transition) {
|
||||
transition.removeListener(this);
|
||||
setViewVisibility(mSharedElements, View.INVISIBLE);
|
||||
ViewGroupOverlay overlay = getDecor().getOverlay();
|
||||
if (mSharedElementSnapshots != null) {
|
||||
@@ -196,8 +197,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mIsCanceled = true;
|
||||
mActivity.finish();
|
||||
mActivity = null;
|
||||
finish();
|
||||
}
|
||||
};
|
||||
mHandler.sendEmptyMessageDelayed(MSG_CANCEL, MAX_WAIT_MS);
|
||||
@@ -269,6 +269,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
|
||||
viewsTransition.addListener(new ContinueTransitionListener() {
|
||||
@Override
|
||||
public void onTransitionEnd(Transition transition) {
|
||||
transition.removeListener(this);
|
||||
exitTransitionComplete();
|
||||
if (mIsHidden) {
|
||||
setViewVisibility(mTransitioningViews, View.VISIBLE);
|
||||
@@ -295,6 +296,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
|
||||
sharedElementTransition.addListener(new ContinueTransitionListener() {
|
||||
@Override
|
||||
public void onTransitionEnd(Transition transition) {
|
||||
transition.removeListener(this);
|
||||
sharedElementTransitionComplete();
|
||||
if (mIsHidden) {
|
||||
setViewVisibility(mSharedElements, View.VISIBLE);
|
||||
@@ -364,15 +366,31 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator {
|
||||
|
||||
private void finishIfNecessary() {
|
||||
if (mIsReturning && mExitNotified && mActivity != null && mSharedElementSnapshots == null) {
|
||||
mActivity.finish();
|
||||
mActivity.overridePendingTransition(0, 0);
|
||||
mActivity = null;
|
||||
finish();
|
||||
}
|
||||
if (!mIsReturning && mExitNotified) {
|
||||
mActivity = null; // don't need it anymore
|
||||
}
|
||||
}
|
||||
|
||||
private void finish() {
|
||||
mActivity.mActivityTransitionState.clear();
|
||||
// Clear the state so that we can't hold any references accidentally and leak memory.
|
||||
mHandler.removeMessages(MSG_CANCEL);
|
||||
mHandler = null;
|
||||
mActivity.finish();
|
||||
mActivity.overridePendingTransition(0, 0);
|
||||
mActivity = null;
|
||||
mSharedElementBundle = null;
|
||||
if (mBackgroundAnimator != null) {
|
||||
mBackgroundAnimator.cancel();
|
||||
mBackgroundAnimator = null;
|
||||
}
|
||||
mExitSharedElementBundle = null;
|
||||
mSharedElementSnapshots = null;
|
||||
clearState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Transition getViewsTransition() {
|
||||
if (mIsReturning) {
|
||||
|
||||
Reference in New Issue
Block a user