Login.setOnClickListener(View.OnClickListener {
val id = ID.getText().toString()
val pw = Password.getText().toString()
val responseListener =
Response.Listener<String?> { response ->
try {
val jsonObject = JSONObject(response)
val success = jsonObject.getBoolean("success")
if (success) {
val msg = jsonObject.getString("nickName")
val userInd = jsonObject.getString("userInd")
Toast.makeText(applicationContext, "success. ID :$msg", Toast.LENGTH_SHORT).show()
val intent = Intent(this@MainActivity,LoginActivity::class.java)
intent.putExtra("UserInd",userInd)
Log.d("MainActivity", "UserInd: $userInd")
startActivity(intent)
finish()
} else {
Toast.makeText(applicationContext, "fail", Toast.LENGTH_SHORT).show()
return@Listener
}
} catch (e: JSONException) {
e.printStackTrace()
Toast.makeText(applicationContext, "except 1", Toast.LENGTH_SHORT).show()
return@Listener
} catch (e: Exception) {
e.printStackTrace()
}
}
val loginRequestActivity = LoginRequestActivity(id, pw, responseListener)
val queue = Volley.newRequestQueue(applicationContext)
queue.add(loginRequestActivity)
})
在MainActivity.kt中
和
val intent = intent val UserInd: String? = intent.getStringExtra("UserInd") Log.d("BookInsertActivity", "UserInd: $UserInd")
在 BookInsert.kt 中 如果 userInd 是一个整数(integer),那么在检索它时也应该得到正确的类型。例如:
val UserInd: Int = intent.getIntExtra("UserInd",0)