不会内存溢出的Android Handler写法
private static class ThisHandler extends Handler {
private final WeakReference<MainActivity> wrActivity;
@Override
private void handleMessage() {
MainActivity act = wrActivity.get();
if(act != null) {
// TODO
}
}
private final WeakReference<MainActivity> wrActivity;
@Override
private void handleMessage() {
MainActivity act = wrActivity.get();
if(act != null) {
// TODO
}
}
}
注意Activity onDestory()的时候将ThisHandler置为null