Почему sendSuccess(JSONObject response)
не выполняется после OnCreate()
вызова?Я хочу получить ответ, но sendSuccess
не работает в MainAcitivity
.
WebManager.java
public class WebManager {
WebManagerInterface mWebManagerInterface;
public static WebManager getInstance() {
return new WebManager();
}
public void getLogin(Context context,WebManagerInterface managerInterface)
{
mWebManagerInterface = mWebManagerInterface;
String url = Constants.DOMAIN_NAME+Constants.GET_LOGIN;
makeWebRequest(context,url,Request.Method.POST,true);
}
private void makeWebRequest(final Context context, final String URL, final int requestMethod, final boolean isScreenVisible) {
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(requestMethod, URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//CustomProgressBar.getInstance(context).hideDialog();
//progress bar
try {
if (response.getString("status").equals(Constants.OK_STATUS)) {
mWebManagerInterface.sendSuccess(response);
// retryCount=0;
} else {
mWebManagerInterface.sendFailure(context.getResources().getString(
R.string.api_failure_message));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//CustomProgressBar.getInstance(context).hideDialog();
if (error instanceof TimeoutError)
{
if (retryCount < maxretry) {
makeWebRequest(context, URL, requestMethod, isScreenVisible);
retryCount++;
} else {
mWebManagerInterface.sendFailure(context.getResources().getString(
R.string.api_failure_message));
}
}
}
});
SingeltonRequestQueue.getInstance().addToRequestQueue(context, jsObjRequest);
} else {
mWebManagerInterface.sendNetworkFailure(false);
}
}
}
WebManagerInterface.java
public interface WebManagerInterface {
void sendSuccess(JSONObject response);
void sendFailure(String error);
void sendNetworkFailure(boolean isInterNetAvailableFlag);
}
MainActivity.java
MainActivity implements WebManagerInterface{
OnCreate(){
WebManager.getInstance().getLogin(getApplicationContext(), this);
}
}