I am newbie to android development. I am using android studio
for developing an application. Things i have done
DB
with two ta
First add the dependencies in build gradle (app)
implementation 'com.mcxiaoke.volley:library:1.0.16'
Then follow the below code:
final ProgressDialog loading = ProgressDialog.show(getActivity(), "", "Please wait...", false, false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, ServerLinks.TOTAL_COUNT_URL, new Response.Listener() {
@Override
public void onResponse(String response) {
loading.dismiss();
try {
JSONObject jsonObject = new JSONObject(response);
String status = jsonObject.getString("status");
if (status.equals("success")) {
String data = jsonObject.getString("data");
JSONObject jsonObject1 = new JSONObject(data);
String male = jsonObject1.getString("male");
String female = jsonObject1.getString("female");
} else {
// no_data_found.setVisibility(View.VISIBLE);
Toast.makeText(getActivity(), "No Data Found", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}//onResponse()
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
loading.dismiss();
//Toast.makeText(getActivity(), "Check Your Internet Connection", Toast.LENGTH_SHORT).show();
}
});
int socketTimeout = 30000; // 30 seconds. You can change it
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
requestQueue.add(stringRequest);