2017-08-18 16 views
0

ApiのJSONの解析にレトロフィットを使用しています。私はモバイルネットワーク(WIFIではない)を使用しているときに、APIからの応答を取得するためにクエリを作成しているときに時々エラーが発生することがあります。モバイルネットワークで継続的なクエリが正常に機能しない

コード:

userLogin("Username"). 
       enqueue(new RetrofitCallback<PatientModel>() { 
        @Override 
        public void onSuccess(PatientModel result) { 
         if (null != result) { 
          loginResponse(result); 
         } 
        } 

        @Override 
        public void onFailure(int code, String msg) { 

        } 

        @Override 
        public void onThrowable(Throwable t) { 

        } 

        @Override 
        public void onFinish() { 
         hideProgress(); 
        } 
       }); 

答えて

0

たぶん、あなたは時間を増やす必要があります。これを試してください:

Gson gson = new GsonBuilder() 
      .setDateFormat("yyyy-MM-dd'T'HH:mm:ss") 
      .create(); 
    okHttpClient = new OkHttpClient().newBuilder() 
      .connectTimeout(120, TimeUnit.SECONDS) 
      .readTimeout(120, TimeUnit.SECONDS) 
      .writeTimeout(120, TimeUnit.SECONDS) 
      .build(); 
    retrofit = new Retrofit.Builder() 
      .baseUrl(Constants.BASE_URL).client(okHttpClient) 
      .addConverterFactory(GsonConverterFactory.create(gson)) 
      .build(); 
    apiService = retrofit.create(IService.class); 
+0

はい私は1分間TimeOutを使用しています。 –

関連する問題