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 项目的构建 项目的构建 ...
随机推荐
- maven02 命令
- javascript 中 offsetWidth,clientWidth;offsetHeight,clientHeight的区别
javascript 中 offsetWidth 是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变 clientWidth.offsetWidth.clientHeight区别IE6.0.FF ...
- AjaxHelper学习,ajax,microsoft,mvc,asp.net
index.cshtml @using (Ajax.BeginForm("ContentAjax", new AjaxOptions { UpdateTargetId = &quo ...
- VMware下桥接设置
操作环境 主机:Win7 X86 SP1 虚拟机:VMware station 8 虚拟机里的系统:Fedora 15 环境上,不管什么系统,什么版本的虚拟机,使用上都是大同小异的,毕竟核心是不变的. ...
- adb server didn t ack failed to start daemon
关掉Ecilpse,打开cmd命令行 1)cd到sdk的platform-tools目录下, 2)执行 adb kill-server ,出现 server not runing 提示 3)执行 ...
- 简述UITextField的属性和用法
0. enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. 1.borderStyle ...
- C# 3循环 for语句
循环:可以反复执行某段代码,直到不满足循环条件为止. 一.循环的四要素:初始条件.循环条件.状态改变.循环体. 1.初始条件:循环最开始的状态. 2.循环条件:在什么条件下进行循环,不满足此条件,则循 ...
- aspnetpager分页,不使用存储过程
一.前台显示界面代码Default.aspx(注意,代码运行环境是VS.2005) <%@ Page Language="C#" AutoEventWireup=" ...
- 初学Django
纵然有众多大牛写过这些简单入门文章,但作为记录,还是要自己动手写下来的比较靠谱,‘好脑筋不如烂笔头’啊! Python 安装 Django本身是纯Python编写的,所以安装框架的第一步是确保你已经安 ...
- Camera实现预览、拍照
1.利用Intent方法实现拍照并保存 在菜单或按钮的选择操作中调用如下代码,开启系统自带Camera APP,并传递一个拍照存储的路径给系统应用程序,具体如下: imgPath = "/s ...