Stetho is facebook open sourced debug tool that brings in chrome developer features
natively for android applications with the help of okhttp interceptors.
Getting started
To get started add dependency in your gradle file and intialize stetho in the onCreate method of your application class.
Adding dependency:
Code changes:
Side notes: (i)If you have never used okHttpClient,enqueue callback returns the response in background thread
, make sure you communicate to the main thread,i have used handler for the purpose.
(ii)If you are using Picasso to display the images in your application make sure you use the same okhttp instance that has StethoInterceptor configured in it. personally i would recommend using Singleton pattern to get instance of okhttp.
make a note that i have used OkHttp3Downloader
.
(iii)Do not configure okhttp in the following way
in okhttp3 the networkInterceptors list is made unmodifiableList. hence will throw
unsupported Operation Exception
.
The video
gives the quickoverview on how stetho helps in monitoring network calls, and inspecting elements in the screens.
Notes
You can additionally view the shared preferences value and the database values using the stetho which i have not included in the video.
In the sample application i have created two dummy methods.fillDummyValuesInSharedPreferences
and fillDummyValuesInDB
which fills value in SharedPreferences. Realm db
contents will not be shown,while shared preferences will be shown under local storage
option, and also note that stetho also provides custom dumpapp plugins
, which i have not covered in this blog post.
More Reading:
1.Also there is awesome screencast by Donn felker called caster.io.
2.Do checkout the sample code in the stetho repo.