java - 成功注册到应用程序后,Android Activity 没有变化
问题描述
我创建了一个具有注册活动的应用程序。当我点击应用程序上的注册按钮时,用户的详细信息被插入到数据库中,但活动不会改变。对于应用程序上的登录,活动按预期从登录活动更改为主页活动,但对于注册活动则没有。
这是代码:
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>(){
@Override
public void onResponse(String response) {
Toast.makeText(register.this, response, Toast.LENGTH_SHORT).show();
if (response.equals("success")) {
Toast.makeText(register.this, response, Toast.LENGTH_LONG).show();
btnRegister.setClickable(false);
Intent intent = new Intent(register.this, MainActivity.class);
startActivity(intent);
finish();
} else if (response.equals("failure")) {
tvStatus.setText("Registration unsuccesful!");
Toast.makeText(register.this, response, Toast.LENGTH_SHORT).show();
}
}
}
解决方案
在我看来,您的回答可能不是您所期望的,我没有使用您使用的侦听器,但是通过查看其他一些问题,我发现了这一点:
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
所以请检查这是否适合你,而不是
if (response.equals("success")) {
这个:
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
}else{
}
您可能需要围绕它添加一个 try/catch。
推荐阅读
- microsoft-graph-api - 有没有办法使用 Outlook Rest API 列出用户的共享邮箱?
- javascript - 如何使用 jQuery 调用 vbscript 函数?
- regex - 将提取的文本字符串转换为 Postgres 中字符串长度不同的日期
- android - Using Firebase in a multi-module project
- xslt-1.0 - How to remove Namespaces when copying nodes to a different node in XML through XSLT1.0?
- javascript - 有什么方法可以与 graphql 查询字段相反?
- python - About custom operations in Tensorflow and PyTorch
- javascript - Having pagination issue in Vue / Laravel
- php - Laravel AdminLTE - How to call method and use its data in view
- git - 在gerrit中重命名一个分支