onResume()内部的Web服务调用无法正常工作

时间:2017-01-20 11:48:20

标签: android retrofit onresume

每次当我回到活动时,我都使用b方法来调用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()

请注意“Log.e(”response“,”Execute1“)的评论;”线。

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,花了差不多一天但最后我试图禁用Instant Run并发布修复版。