I decided to spend a few hours on Stetho.
Stetho is a sophisticated debug bridge for Android applications.
How to enable it
It's very simple to enable Stetho.
Just add these lines to your build.gradle
:
{ //Stetho core ' com.facebook.stetho:stetho:1.1.1 '//if you want to add a network helper ' com.facebook.stetho:stetho-okhttp:1.1.1 '}
Then on your application you can enable the tool just adding:
Stetho.Initialize( stetho. (thisenabledumpapp ( stetho . defaultdumperpluginsprovider (this . ( stetho. Defaultinspectormodulesprovider (thisbuild ())
In my simple application, I has 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 of your 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 can see the Elements tab.
Here's the can navigate in the elements inside your Activity ...
Here a first surprise...clicking on the entry on the tab, the element was highlighted on the device!
The Network tab.
If you work with the Chrome Developer Tools, your know it very well. Here's can see the network calls with their data.
In my app I do a simple call with Okhttp
OkhttpclientClient= New Okhttpclient();Client.Networkinterceptors().Add(New Stethointerceptor()); RequestRequest= New Request.Builder() .Url("Https://google.com") .Build();Client.Newcall(Request).Enqueue(New Callback() { @Override Public voidOnFailure(request Request, Ioexception E) { //do something } @Override Span class= "PLN" > public void onresponse< Span class= "pun" > (response Response) ioexception { // Do something } });
Here the tab:
The Resources tab.
In my sample app I am setting a simple value in the sharedpreferences.
Sharedpreferenceseditor Editor = Getsharedpreferences ( "TEST" , Mode_private). Span class= "PLN" >edit (); Editor. ( "name" , " Paolo "); Editor. ( "idname" , 12< Span class= "pun"); Editor.
You can check this value in the navigating in the Local Storage entry.
Also I use a simple sqliteopenhelper to manage a very small the database with just a table.
Private StaticFinalStringCreate_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 voidOnCreate(SqlitedatabaseDb) {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)" ); } /span>
You can navigate on the data on the Websql entry.
And you can run queries on your db ... (!)
Of course it was only a first glance at this tool but it was enough to check the power of this debug tool.
Transferred from: http://gmariotti.blogspot.it/2015/07/a-first-glance-at-stetho-tool.html
Getting Started with the Facebook Debug tool stetho Configuration