Facebook 调试工具Stetho配置入门
I decided to spend a few hours on Stetho.
Stetho is a sophisticated debug bridge for Android applications.
How to enable it
It is very simple to enable Stetho.
Just add these lines to your build.gradle:
dependencies {
// Stetho core
compile 'com.facebook.stetho:stetho:1.1.1'
//If you want to add a network helper
compile 'com.facebook.stetho:stetho-okhttp:1.1.1'
}
Then in your Application you can enable the tool just adding:
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(
Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(
Stetho.defaultInspectorModulesProvider(this))
.build());
In my simple application, I have a network call with okhttp-client , a simple value in the shared preferences, and a small db with one table.
Now the last step: Run the application and just open Chrome on your pc (where the device is plugged).
In your chrome just navigate on chrome://inspect
As you can see in the image you can see 2 apps running in my device (I love Nexus4 for this kind of tests....)
- Chrome
- My Stetho Test App
How can I use it
Here you can open a magical world...clicking the inspect link.
First of all you can see the elements tab.
Here you can navigate in the elements inside your Activity......
Here a first surprise...clicking on the entry on the tab, the element is highlighted on the device !
The network tab.
If you work with the Chrome Developer Tools, you know it very well. Here you can see the network calls with their data.
In my app I do a simple call with okhttp
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor()); Request request = new Request.Builder()
.url("https://google.com")
.build(); client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
//do something
} @Override
public void onResponse(Response response) throws IOException {
//do something
}
});
Here the tab:
The Resources tab.
In my sample app I am setting a simple value in the SharedPreferences.
SharedPreferences.Editor editor = getSharedPreferences("TEST", MODE_PRIVATE).edit();
editor.putString("name", "Paolo");
editor.putInt("idName", 12);
editor.commit();
You can check this value in the navigating in the Local Storage entry.
Also I use a simple SQLiteOpenHelper to manage a very small database with just a table.
private static final String CREATE_DATABASE = "CREATE TABLE " + TBL_USR + " ( " +
TBL_USR_CLMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " +
TBL_USR_CLMN_NAME + " TEXT NOT NULL, " +
TBL_USR_CLMN_SURNAME + " TEXT NOT NULL, " +
TBL_USR_CLMN_CODE + " INTEGER NOT NULL DEFAULT 0 " +
")"; @Override
public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_DATABASE);
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO1','ROSSI1', 233432 )");
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO2','ROSSI2', 103213 )");
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO3','ROSSI3', 5454331 )");
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO4','ROSSI4', 5454444 )");
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO5','ROSSI5', 1231232 )");
db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO6','ROSSI6', 4443343 )"); }
You can navigate on the data on the WebSQL entry.
And you can run queries on your db...(!)
Of course it is only a first glance at this tool but it is enough to check the power of this debug tool.
转自:http://gmariotti.blogspot.it/2015/07/a-first-glance-at-stetho-tool.html
Facebook 调试工具Stetho配置入门的更多相关文章
- nginx配置入门
谢谢作者的分享精神,原文地址:http://www.nginx.cn/591.html nginx配置入门 之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一 ...
- echart图表控件配置入门(二)常用图表数据动态绑定
上一节 <echart图表控件配置入门(一)>介绍了echarts图表控件的入门配置,使开发人员可以快速搭建出一个静态的图表.但是在实际开发过程这还是不够的,不可能所有的图表控件都是静态数 ...
- echart图表控件配置入门(一)
现在主流的web图表控件主要有hightchart.fusionchart.echart: echart作为百度前端部门近期推出的一个基于html5的免费图表控件,以其丰富图表类型和良好的兼容性速度得 ...
- spring的Java配置入门(Spring Boot学习笔记之一)
spring的Java配置 1.创建maven项目 使用idea创建maven项目,这里顺便提一下,idea真的比eclipse好用,早点熟悉吧.然后就是maven是java项目管理最主流的工具,自己 ...
- nginx 配置入门
之前的nginx配置是对nginx配置文件的具体含义进行讲解,不过对于nginx的新手可能一头雾水. 今天看到个文档不错,翻译过来分享给大家,可以让新手更详细地了解nginx配置,可以说是nginx配 ...
- Git客户端的安装与配置入门
GitLab与Git客户端的安装与配置入门,每次配置完一段时间,就忘记配置过程了,为了自己和同学们以后有所参照,特记录了本次下载和配置,其实Git就是一个版本控制系统,类似于SVN,CVS等 下载:W ...
- 转载:Vim 配置入门
转载:Vim 配置入门 原文地址:http://www.ruanyifeng.com/blog/2018/09/vimrc.html 作者: 阮一峰 Vim 是最重要的编辑器之一,主要有下面几个优点. ...
- fis3前端工程构建配置入门教程
一.前言 fis3是百度推出的一款前端工程构建工具,类似的还有webpack,gulp等工具:无论大家有没有使用过,从事前端行业应该都略知一二了,所以对于此类工具用干嘛的我这里就不做重复了. 其实对于 ...
- Maven学习归纳(一)——简单的环境配置入门
一.Maven的基本概念 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的编译,测试,构建,报告和文档的软件项目管理工具和解决依赖关系的工具. 1.1 项目的构建 项目的构建 ...
随机推荐
- Map集合重要练习
重要练习:将字符串中的字母按如下格式显示: a(1)b(2)...... 代码及思路如下: /* 获取字符串中字母的次数,并打印出如下格式a(1)b(2)c(3)...... 思路: 先定义一个方法, ...
- JQuery(一)——初步总结
JQuery其实早就看过相关的视频了,但是由于当时查的资料太少,理解的不够深刻,所以没有进行总结,这次回过头来又学习了,心里感觉理解了很多,因为BS的其它知识基本学习完了,而且有了一定程度的理解.相互 ...
- zepto 获取select选中的值
jQuery中典型的方法: $('option[selected]') 不管用,因为selected并不是CSS标准. 因此,在zepto中想要获取select元素中选中的option,需采取如下 ...
- dom处理配置文件_待完善
import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java ...
- iOS各种类
http://www.isenhao.com/xueke/jisuanji/bcyy/objc.php http://www.code4app.com 这网站不错,收集各种 iOS App 开发可以用 ...
- 关于C语言指针几个容易混淆的概念
前言: 大多数学习过C/C++或者正在学习的同学在对指针概念把握时,总是感觉不太明了,小弟我也不例外啊,于是翻开资料复习整理一下,并把自己的学习心得拿出来供大家分享,讨论. 基本概念掠过,主要来探讨一 ...
- 用document.title=“xxx”动态修改title,在ios的微信下面不生效的解决办法!
//需要jQuery var $body = $('body'); document.title = 'title'; // hack在微信等webview中无法修改document.title的情况 ...
- 中国25位最具影响力的IC人物
当今许多企业的领导者几乎已经成为其企业的代名词,而在芯片业,我们听说的更多的是“龙芯”.“国芯”,他们的领导者的声音却鲜有传出.芯片业透出的强烈的民族色彩,也使这些隐身的企业家们的注意力更聚集在研发上 ...
- javascript函数值的重写
原文:javascript函数值的重写 javascript函数值的重写 定义了一个函数,需要重写这个函数并使用原先的函数值.做法是: 1.定义一个变量让原先函数的值指向它,把原先函数的指向一个新的函 ...
- mysql utf8 中文
#!/usr/bin/perl use DBI; use Encode; $user="root"; $passwd="1234567"; $dbh=" ...