博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Facebook 调试工具Stetho配置入门
阅读量:6701 次
发布时间:2019-06-25

本文共 3649 字,大约阅读时间需要 12 分钟。

I decided to spend a few hours on .

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 + " "

转载地址:http://wpgoo.baihongyu.com/

你可能感兴趣的文章
【转】[教程] CSS入门3:如何插入CSS样式
查看>>
5shift shell
查看>>
ubuntu14.04配置caffe
查看>>
Quartz 2D编程笔记
查看>>
bzoj2561 最小生成树
查看>>
java MD5加密
查看>>
我的Android进阶之旅------>Android利用温度传感器实现带动画效果的电子温度计
查看>>
Kickstart Practice Round 2017---A
查看>>
Q-Dir
查看>>
谁获得了最高奖学金
查看>>
python3基础3--数据类型--数据运算--表达式if -else-while-for
查看>>
浮动问题
查看>>
hausaufgabe--python 18- Defined specific Functions
查看>>
Django的视图层
查看>>
转:Yupoo(又拍网)的系统架构
查看>>
.读取excel表格(JAVA)
查看>>
【英语-刘晓艳-词汇】词汇06
查看>>
模块化
查看>>
iPad开发--QQ空间,处理横竖屏布局,实现子控件中的代理
查看>>
Win10无法使用小娜搜索本地应用问题的解决方案
查看>>