android个人笔记之leakcanary初始化

来源:互联网 发布:种子文件下载软件 编辑:程序博客网 时间:2024/05/13 09:06

1.在工程gradle加上后面2句

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0'    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'}
2.在自己定义的application这样写
public void onCreate() {    super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {    // This process is dedicated to LeakCanary for heap analysis.    // You should not init your app in this process.    return;}
refWatcher = LeakCanary.install(this);}public static RefWatcher getRefWatcher(Context context) { MApplication application = (MApplication) context.getApplicationContext(); return application.refWatcher;}private RefWatcher refWatcher;
3.在activity的ondestory里面这样写
@Overrideprotected void onDestroy() {    super.onDestroy();    RefWatcher refWatcher = MApplication.getRefWatcher(this);    refWatcher.watch(this);}
eclipse 看这里:
http://blog.csdn.net/liudehuaii18/article/details/46287695

0 0
原创粉丝点击