-
-
Save jankovd/891d96f476f7a9ce24e2 to your computer and use it in GitHub Desktop.
Fixes a leak caused by AudioManager using an Activity context, see https://github.com/square/leakcanary/issues/205
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActivityUsingVideoView extends Activity { | |
@Override protected void attachBaseContext(Context base) { | |
super.attachBaseContext(AudioServiceActivityLeak.preventLeakOf(base)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fixes a leak caused by AudioManager using an Activity context. | |
* Tracked at https://android-review.googlesource.com/#/c/140481/1 and | |
* https://github.com/square/leakcanary/issues/205 | |
*/ | |
public class AudioServiceActivityLeak extends ContextWrapper { | |
AudioServiceActivityLeak(Context base) { | |
super(base); | |
} | |
public static ContextWrapper preventLeakOf(Context base) { | |
return new AudioServiceActivityLeak(base); | |
} | |
@Override public Object getSystemService(String name) { | |
if (Context.AUDIO_SERVICE.equals(name)) { | |
return getApplicationContext().getSystemService(name); | |
} | |
return super.getSystemService(name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This didn't work