我正在尝试使用排球库登录。我使用SharedPrefrences来存储用户名,电子邮件,手机。当我使用正确的手机号码时。和密码。 Toast生成登录成功,但无法将Login Fragment移动到仪表板活动。无法在Volley Library中使用Intent从片段中移动下一个活动
这里是登录方法的代码
private void login(String login_url, final String getLoginMob, final String getLoginPwd) {
//Progress Dialog code
final Dialog dialog =new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loading_dialog);
dialog.setCancelable(false);
dialog.show();
RequestQueue queue = Volley.newRequestQueue(getActivity());
StringRequest postrequest = new StringRequest(Request.Method.POST, login_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
dialog.dismiss();
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getBoolean("success") == true) {
Toast.makeText(getActivity(),jsonObject.getString("message"),Toast.LENGTH_LONG).show();
JSONObject jsonObjectInfo=jsonObject.getJSONObject("User");
sharedPrefrence_main.setName(jsonObjectInfo.getString("name"));
sharedPrefrence_main.setEmail(jsonObjectInfo.getString("email"));
sharedPrefrence_main.setMobile_no(jsonObjectInfo.getString("mobile"));
Intent intent=new Intent(getActivity(), Dashboard.class);
startActivity(intent);
} else if (jsonObject.getBoolean("success") == false) {
Toast.makeText(getActivity(), jsonObject.getString("message"), Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getActivity(),"Entries are wrong",Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
dialog.dismiss();
}
}){
@Override
protected Map<String, String> getParams(){
Map<String,String> param=new HashMap<String, String>();
param.put("mobile_email", getLoginMob);
param.put("password", getLoginPwd);
return param;
}
};
int socketTimeout = 30000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
postrequest.setRetryPolicy(policy);
queue.add(postrequest);
}
JSON响应
{ “成功”: “真”, “消息”: “登录成功地”, “用户”:[{ “名”: “satishkanaujiya”, “电子邮件”: “***** @ gmail.com”, “手机”: “901589 ****”}]}
你应该getActivity()。startActivity(意向) –
@Sandeepdhiman我试过,但没有帮助做到这一点。 – Codelover