Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handler #13

Closed
ibosong opened this issue May 19, 2017 · 0 comments
Closed

Handler #13

ibosong opened this issue May 19, 2017 · 0 comments

Comments

@ibosong
Copy link

ibosong commented May 19, 2017

Handler机制有一个特点是不会随着Activity、Service的生命周期结束而结束。也就是说,如果你Post了一个Delay的Runnable,然后在Runnable执行之前退出了Activity,Runnable到时间之后还是要执行的。如果Runnable里面包含更新View的操作,程序崩溃了。

Runnable里强引用到View,会阻止Activity或Service销毁,在Runnable执行完之后才会销毁,所以造成内存泄露。而如果引用的View是使用WeakReference才会有崩溃的情况,需要判断View是否为null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant