频道栏目
首页 > 资讯 > 其他 > 正文

LeakCanary的用法

17-04-21        来源:[db:作者]  
收藏   我要投稿

1、添加依赖

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'

releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'

2、Application中初始化leakcanary

//在自己的Application中添加如下代码

public static RefWatcher getRefWatcher(Context context) {

App application = (App) context.getApplicationContext();

return application.refWatcher;

}

//在自己的Application中添加如下代码

private RefWatcher refWatcher;

@Override

public void onCreate() {

super.onCreate();

//在自己的Application中添加如下代码

refWatcher = LeakCanary.install(this);

}

3、Activity中使用

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//在自己的应用初始Activity中加入如下两行代码

RefWatcher refWatcher = MyApp.getRefWatcher(this);

refWatcher.watch(this);

}

 

相关TAG标签
上一篇:反编译APK中的图片资源
下一篇:DailyDictionary Mars常用控件
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站