앱이 실행되지만 특정 기능이 없습니다. 로그인 또는 계정 등록을 시도 할 때마다 Gradle 콘솔에 프레임이 건너 뛰고 너무 많이 실행되고 있다고 표시됩니다. 내가하려는 것은 사용자 정보를 받아서 데이터베이스로 보내는 것입니다. 이것은 문제가있는 레지스터 활동 코드입니다. JSON을 꺼내서 새로운 활동을 열어두면 작동합니다. 등록에 대한Android Studio 앱 데이터베이스를 통해 실행되지 않음
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
RegisterActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setMessage("Register Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
RegisterRequest registerRequest = new RegisterRequest(username, email, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
queue.add(registerRequest);
}
});
}
}
PHP 코드 :
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO data (username, email, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "sss", $username, $email, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
등록 요청 코드 :이
private Map<String, String> params;
public RegisterRequest(String username, String email, String password, Response.Listener<String> listener){
/*
NExt line means we are going to pass some information into the register.php
*/
super(Method.POST, REGISTER_REQUEST_URL, listener, null);
/*
This is how we pass in the information from the register to the thing, we are using a hashmap
*/
params = new HashMap<>();
params.put("username", username);
params.put("email", email);
params.put("password", password);
}
/*
Volley needs to get the data so we do a get params
Which gives us this method
*/
@Override
public Map<String, String> getParams() {
return params;
}
}
사람이 내가이 문제를 해결하는 방법을 알고 있나요 ??? 이 비동기 작업을 입력하는 방법을 모르겠다. 누구든지 도움을 요청하십시오. 어쨌든 비동기 작업없이이 문제를 해결할 수 있습니까? 감사합니다!
감사합니다. 작동하는지 말해 드리겠습니다 !!! –
작동하는 경우 질문에 답변하지 않도록 답변을 수락하십시오 :) –