Destroy activity/view references to avoid memory leak
Bug: 204891006 Change-Id: If60ac1716c30ebe68fb6e7457d71f542d3075422
This commit is contained in:
parent
b15d3cfe73
commit
573fca80f6
|
@ -55,6 +55,7 @@ import android.animation.AnimatorListenerAdapter;
|
||||||
import android.animation.AnimatorSet;
|
import android.animation.AnimatorSet;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -96,6 +97,7 @@ import com.android.quickstep.GestureState.GestureEndTarget;
|
||||||
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
|
import com.android.quickstep.RemoteTargetGluer.RemoteTargetHandle;
|
||||||
import com.android.quickstep.util.ActiveGestureLog;
|
import com.android.quickstep.util.ActiveGestureLog;
|
||||||
import com.android.quickstep.util.ActivityInitListener;
|
import com.android.quickstep.util.ActivityInitListener;
|
||||||
|
import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
|
||||||
import com.android.quickstep.util.AnimatorControllerWithResistance;
|
import com.android.quickstep.util.AnimatorControllerWithResistance;
|
||||||
import com.android.quickstep.util.InputConsumerProxy;
|
import com.android.quickstep.util.InputConsumerProxy;
|
||||||
import com.android.quickstep.util.InputProxyHandlerFactory;
|
import com.android.quickstep.util.InputProxyHandlerFactory;
|
||||||
|
@ -153,6 +155,17 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
|
||||||
protected MultiStateCallback mStateCallback;
|
protected MultiStateCallback mStateCallback;
|
||||||
protected boolean mCanceled;
|
protected boolean mCanceled;
|
||||||
private boolean mRecentsViewScrollLinked = false;
|
private boolean mRecentsViewScrollLinked = false;
|
||||||
|
private final ActivityLifecycleCallbacksAdapter mLifecycleCallbacks =
|
||||||
|
new ActivityLifecycleCallbacksAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onActivityDestroyed(Activity activity) {
|
||||||
|
if (mActivity != activity) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mRecentsView = null;
|
||||||
|
mActivity = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private static int getFlagForIndex(int index, String name) {
|
private static int getFlagForIndex(int index, String name) {
|
||||||
if (DEBUG_STATES) {
|
if (DEBUG_STATES) {
|
||||||
|
@ -416,6 +429,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
|
||||||
setupRecentsViewUi();
|
setupRecentsViewUi();
|
||||||
linkRecentsViewScroll();
|
linkRecentsViewScroll();
|
||||||
|
|
||||||
|
mActivity.registerActivityLifecycleCallbacks(mLifecycleCallbacks);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,6 +1556,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
mStateCallback.setStateOnUiThread(STATE_HANDLER_INVALIDATED);
|
mStateCallback.setStateOnUiThread(STATE_HANDLER_INVALIDATED);
|
||||||
|
if (mActivity != null) {
|
||||||
|
mActivity.unregisterActivityLifecycleCallbacks(mLifecycleCallbacks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.android.launcher3.util;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.Application.ActivityLifecycleCallbacks;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public interface ActivityLifecycleCallbacksAdapter extends ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
default void onActivityCreated(Activity activity, Bundle bundle) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivityDestroyed(Activity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivityPaused(Activity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivityResumed(Activity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivityStarted(Activity activity) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onActivityStopped(Activity activity) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue