2016-12-19 24 views
1

我的項目已正確配置爲使用Stetho。之前它在工作。

但現在當我檢查我的應用程序的UI檢查(元素部分)它不起作用。而其他部分的工作,如資源。
另外DevTools顯示我的應用程序的屏幕,但元素部分是空的。我不知道哪些更改禁用了stetho Elements。

Stetho和Chrome之間有衝突嗎?如果是這樣,哪些版本兼容?目前我使用stehto 1.4.2和chrome v55。
任何解決方案,將不勝感激。提前致謝。Facebook Stetho庫不適用於檢查用戶界面

回答

0

爲了實施改造Singleton設計模式與Stetho網絡攔截器實例一起看看下面的代碼:

public class ApiClient extends Application { 

    private static ApiClient apiClient = null; //singleton Object 
    String apiURL = "http://your.url/"; 


    public static ApiClient getApiClient() {//getter for object 
     if (apiClient == null) 
      apiClient = new ApiClient(); 
     return apiClient; 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     Stetho.initializeWithDefaults(this); 
    } 

    public Retrofit getClient() {//Retrofit instance 
     int myTime = 15; 
     OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder() 
       .connectTimeout(myTime, TimeUnit.SECONDS) 
       .readTimeout(myTime, TimeUnit.SECONDS) 
       .writeTimeout(myTime, TimeUnit.SECONDS) 
       .addNetworkInterceptor(new StethoInterceptor()); 

     Retrofit.Builder builder = new Retrofit.Builder() 
       .baseUrl(apiURL) 
       .client(okHttpBuilder.build()) 
       .addConverterFactory(GsonConverterFactory.create()); 
     return builder.build(); 
    } 
} 

我們使用改裝看到下面的代碼:

LoginDTO loginDTO = new LoginDTO(
      etPhno.getText().toString().trim(), 
      etPass.getText().toString().trim() 
    ); 

ApiService service = ApiClient.getApiClient().getClient().create(ApiService.class); 
Call<LoginResp> call = service.loginAPI(loginDTO); 
call.enqueue(new Callback<LoginResp>() { 

    @Override 
    public void onResponse(Call<LoginResp> call, Response<LoginResp> response) { 

     LoginResp loginResp = response.body(); 

    } 

    @Override 
    public void onFailure(Call<LoginResp> call, Throwable t) { 

     Toast.makeText(Login.this, "Error here", Toast.LENGTH_SHORT).show(); 
    } 
}); 

在ApiService接口聲明如下功能:

@POST("login") 
    Call<LoginResp> loginAPI(@Body LoginDTO loginDTO); 

個LoginDTO類是這樣的:

public class LoginDTO { 
    @SerializedName("log_phno") 
    @Expose 
    private String user; 

    @SerializedName("log_pass") 
    @Expose 
    private String pass; 

    public LoginDTO(String user, String pass) { 
     this.user = user; 
     this.pass = pass; 
    } 

    public String getUser() { 
     return user; 
    } 

    public String getPass() { 
     return pass; 
    } 
} 

現在最重要的部分,去清單文件,並在<application>標籤把你的單身類名在句號之前像這樣(。):

android:name=".Controller.ApiClient" 

並且可以看到Stetho攔截器的魔力,運行您的應用並打開Goog​​le Chrome並鍵入chrome://inspect/

+0

由於Android Profiler的原因,無需使用stetho,它非常強大和全面 – Fartab

相關問題