2017-01-20 4 views
0

私はアクティビティに戻るときに毎回Webサービスを呼び出すためにOnResume()メソッドを使用しています。アプリケーションがフォアグラウンドにあるときにすべて正常に機能しますが、 "時にはそれがnot.belowである私のコードはWebサービスコールがonResume()内で正常に動作しない

private void getRetrofit(final String searchstr){ 
    if(session.getUserRegisterID()==null){ 
     UserRegid="0"; 
    }else{ 
     UserRegid=session.getUserRegisterID(); 
    } 

    ringProgressDialog = ProgressDialog.show(this, "Please wait ...", "Loading Stores ...", true); 
    ringProgressDialog.setCancelable(false); 

    Log.e("response", "Execute1");//Up to this code is executed in issue scenario it is not entering into further and no other logs are called. 

    serviceApi = ServiceGenerator.createService(ApiInterface.class); 
    Call<okhttp3.ResponseBody> call = serviceApi.getStores(new StoreJsonObject(searchstr, SignInActivity.nwLocation.getLatitude()+","+SignInActivity.nwLocation.getLongitude() 
      , UserRegid,session.getRadiousName(),1,10,PageName)); 
    Log.e("response", "Execute2"); 
    call.enqueue(new Callback<okhttp3.ResponseBody>() { 

     @Override 
     public void onResponse(Call<okhttp3.ResponseBody> call, Response<okhttp3.ResponseBody> response) { 
      try { 
       Log.e("response", "Success"); 
      }catch (Exception e) 
      { 
       Log.e("response", "Exception"); 
       e.printStackTrace(); 
       ringProgressDialog.dismiss(); 
      } 
     } 

     @Override 
     public void onFailure(Call<okhttp3.ResponseBody> call, Throwable t) { 
      Log.e("response", "Failed"); 
      ringProgressDialog.dismiss(); 
     } 
    }); 
} 

で、私のonResume()方法は

@Override 
public void onResume() { 
    super.onResume(); 
    getRetrofit(""); 
} 

ある "Log.e(" 応答 "" EXECUTE1);" でコメントを遵守してくださいライン。

+0

Log.eからどのような例外が投げられると思われますか? – AnixPasBesoin

+0

私はこの "Log.e(" response "、" Execute2 ");"という部分のコードを実行していて、コードが実行されているところで私の参照用に保管していました。@ Anix –

+0

確かに、単純なログは例外をスローしません。キャッチブロックは役に立たない。 – AnixPasBesoin

答えて

1

私は同じ問題に直面していて、ほぼ一日過ごしましたが、ついに私はインスタントランを無効にしようとして、修正しました。

+0

を実行すると、即時実行が無効になりますか? –

+0

はい、ファイル>設定>ビルド、実行、展開>インスタント実行> @Harikrishnaのチェックを外してください –

+0

ありがとうございました..あなたは私の日を作ってくれました.... @ piyush –

関連する問題