@@ -9,8 +9,16 @@ http://blog.csdn.net/androidmsky/article/details/53009886
99
1010https://github.com/AndroidMsky/RandomTextView
1111
12- 2016年11-30号,解决内存泄漏问题
12+ 2016年11-30号,解决内存泄漏问题 (v1.3已经没有此问题)
1313
14+ 2017年6月13日,我们加入了对view状态的监听。Activity退出,view自动销毁。不用重写onestroy了
15+ ```
16+ @Override
17+ protected void onDetachedFromWindow() {
18+ super.onDetachedFromWindow();
19+ destroy();
20+ }
21+ ```
1422[ 2.v1.2更新内容] ( #2 )
1523
16242016年11月11号,RandomTextView第一次更新为v1.1版本吧。
@@ -113,7 +121,7 @@ mRandomTextView.setText("909878");
113121```
114122mRandomTextView.setMaxLine(20);
115123```
116- 防止泄漏
124+ 防止泄漏(最新版本不用写此方法了)
117125```
118126 @Override
119127 protected void onDestroy() {
@@ -368,59 +376,9 @@ private final Runnable task = new Runnable() {
368376<h2 id =" 2 " >v1.2更新内容</h2 >
369377v1.2更新内容:
370378解决内存泄漏问题,
371- 看到泄可能有点手抖,不过面对现实。
372- 上图:
373-
374- ![ 这里写图片描述] ( http://img.blog.csdn.net/20161130174054510 )
375-
376- 如果反复选择屏幕让Activty重新创建,就会出现内存泄漏,安利给大家内存泄漏检测工具:leakcanary:https://github.com/square/leakcanary
377- 配置十分简单先是引用:(2016.11.30版本)
378-
379- ```
380- debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
381- releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
382- testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
383- ```
384- 然后:
385-
386- ```
387- public class MyApplication extends Application {
388-
389- @Override
390- public void onCreate() {
391- super.onCreate();
392- if (LeakCanary.isInAnalyzerProcess(this)) {
393- // This process is dedicated to LeakCanary for heap analysis.
394- // You should not init your app in this process.
395- return;
396- }
397- LeakCanary.install(this);
398- }
399- }
400-
401- ```
402- 如果检测activity的泄漏问题,可以开启旋转屏幕一旋转就重新创建activity了,这样就反反复复创建activity。如上图泄漏问题就会被推送出来,而且明确告诉你是什么样一个引用链导致的泄漏。工具很强大有么有。本文框架的问题就是,如果RandomTextview的动画没有停止,那么activity就不会被释放掉,这样就造成了泄漏,所以在activity中写入:
403-
404- ```
405-
406- @Override
407- protected void onDestroy() {
408- super.onDestroy();
409- mRandomTextView.destroy();
410- }
411- ```
412- 并且提供destroy方法:
413-
414- ```
415- public void destroy (){
416- auto=false;
417- handler.removeCallbacks(task);
418-
419- }
420- ```
421379
422380欢迎大家提出各种问题,让控件越来越好用谢谢。
423- 2016.11.30 Androidmsky
381+ 2017.6.13 Androidmsky
424382## License
425383
426384 Copyright 2016 AndroidMsky
0 commit comments