2015年11月

Handler 类应该应该为static类型,否则有可能造成泄露。在程序消息队列中排队的消息保持了对目标Handler类的应用。如果Handler是个内部类,那 么它也会保持它所在的外部类的引用。为了避免泄露这个外部类,应该将Handler声明为static嵌套类,并且使用对外部类的弱应用。

    static class MyHandler extends Handler
{
    WeakReference<PopupActivity> mActivity;
    MyHandler(PopupActivity activity)
    {
        mActivity = new WeakReference<PopupActivity>(activity);
    }
    @Override
    public void handleMessage(Message msg)
    {
        PopupActivity theActivity = mActivity.get();
        switch (msg.what)
        {
        case 0:
            theActivity.popPlay.setChecked(true);
            break;
        }
    }
}
MyHandler ttsHandler = new MyHandler(this);
private Cursor mCursor;

private void test()
{
    ttsHandler.sendEmptyMessage(0);
}

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}][HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}\6.0]
[HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}\6.0\0]
[HKEY_CLASSES_ROOT\TypeLib\{F5078F18-C551-11D3-89B9-0000F81FE221}\6.0\0\win32]
@="c:\\windows\\system32\\msxml6.dll"