[Android] Use a static handler to avoid a memory leak
Ludovic Fauvet
git at videolan.org
Wed May 29 14:27:50 CEST 2013
vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Wed May 29 14:25:47 2013 +0200| [303293b74a46307ed98d72e2b1fbf231b2c72ce8] | committer: Ludovic Fauvet
Use a static handler to avoid a memory leak
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=303293b74a46307ed98d72e2b1fbf231b2c72ce8
---
vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 456f985..bb3da82 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -109,6 +109,8 @@ public class MainActivity extends SherlockFragmentActivity {
private boolean mFirstRun = false;
private boolean mScanNeeded = true;
+ private Handler mHandler = new MainActivityHandler(this);
+
@Override
protected void onCreate(Bundle savedInstanceState) {
if (!LibVlcUtil.hasCompatibleCPU(this)) {
@@ -616,12 +618,19 @@ public class MainActivity extends SherlockFragmentActivity {
}
};
- private final WeakHandler<MainActivity> mHandler = new WeakHandler<MainActivity>(this) {
+ private static class MainActivityHandler extends WeakHandler<MainActivity> {
+ public MainActivityHandler(MainActivity owner) {
+ super(owner);
+ }
+
@Override
public void handleMessage(Message msg) {
+ MainActivity ma = getOwner();
+ if(ma == null) return;
+
switch (msg.what) {
case ACTIVITY_SHOW_INFOLAYOUT:
- mInfoLayout.setVisibility(View.VISIBLE);
+ ma.mInfoLayout.setVisibility(View.VISIBLE);
break;
}
}
More information about the Android
mailing list