搜索
您的当前位置:首页正文

android神器Stetho调试

来源:二三娱乐

// Gradle dependency on Stetho  
dependencies {  compile 'com.facebook.stetho:stetho:1.1.1'  }

public class MyApplication extends Application { public void onCreate() { super.onCreate(); Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp( Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector( Stetho.defaultInspectorModulesProvider(this)) .build()); }}

官网中使用OkHttp为实例,使用如下


OkHttpClient client = new  StethoInterceptor());

compile 'com.facebook.stetho:stetho:1.1.1'compile 'com.facebook.stetho:stetho-okhttp:1.1.1'compile 'com.squareup.okhttp:okhttp:2.3.0'
OkHttpClient client = new  StethoInterceptor());mRequestQueue = Volley.newRequestQueue(getApplicationContext(), new OkHttpStack(client));

public class MyAppliation extends Application {  @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); instance = this; Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) .build()); } /** * @return The Volley Request queue */ public RequestQueue getRequestQueue() { // lazy initialize the request queue, the queue instance will be // created when it is accessed for the first time synchronized (App.class) { if (mRequestQueue == null) { OkHttpClient client = new OkHttpClient();  StethoInterceptor()); mRequestQueue = Volley.newRequestQueue(getApplicationContext(), new OkHttpStack(client)); } } return mRequestQueue; }}

Activity类代码:

public class MainActivity extends Activity { private TextView tv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_main); tv = (TextView)findViewById(R.id.tv); RequestQueue queue = App.getInstance().getRequestQueue(); String url =  StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String s) { LogUtil.d(s); tv.setText(s); } }, new com.android.volley.Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { LogUtil.e(volleyError.toString()); } }); queue.add(request); SharedPrfUtil.setInt("uid",669); SharedPrfUtil.setString("username","dongye"); }}
Stetho调试效果图
调试程序列表
调试网络请求
读取数据存储
Top