我正在尝试使用 Volley 库获取数据以在 Andriod 应用程序中形成服务器。当我请求获取数据时我的数据太大但问题是凌空超时错误我也使用了RetryPolicy但问题是一样的。我该如何解决?
我已经尝试过 RetryPolicy 和 AsynTask,但我的问题无法解决。谁能告诉我如何解决这个问题?//主要功能在这里...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_member);
initiateViews();
searchViewCategory();
}
//initiateViews function...
private void initiateViews() {
recyclerView = findViewById(R.id.search_category_recyle_view);
mSearchView = findViewById(R.id.searchView);
addMember = findViewById(R.id.addMember);
requestQueue = Volley.newRequestQueue(this);
}
private void searchViewCategory() {
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
getData();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
}
//Get Data from Server function
public void getData()
{
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, "http://alfahd.witorbit.net/api.php?search_member=a&array=1", new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObjectresponse)
{
Toast.makeText(SearchMember.this, "" + response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error)
{
error.printStackTrace();
dialog.dismiss();
Toast.makeText(SearchMember.this, "Error", Toast.LENGTH_SHORT).show();
}
});
request.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(request);
}
交互式爱情
相关分类