标签:
解决办法:
public class SampleActivity extends Activity { /** * Instances of static inner classes do not hold an implicit * reference to their outer class. */ private static class MyHandler extends Handler { private final WeakReference<SampleActivity> mActivity; public MyHandler(SampleActivity activity) { mActivity = new WeakReference<SampleActivity>(activity); } @Override public void handleMessage(Message msg) { SampleActivity activity = mActivity.get(); if (activity != null) { // ... } } } private final MyHandler mHandler = new MyHandler(this);
参考:android handler的警告Handler Class Should be Static or Leaks Occur
Handler Should be static or leaks Occur?
标签:
原文地址:http://www.cnblogs.com/tt2015-sz/p/5610164.html