你好,Kotlin 可以参考如下代码,我这边测试是正常的
package com.ywj.tdsdemo
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import cn.leancloud.LCUser
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
class TestActivity : AppCompatActivity() {
private val TAG: String = "TestActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test2)
register()
}
private fun register(){
val user = LCUser()
user.username = "Tom"
user.password = "cat!@#123"
user.email = "tom@leancloud.rocks"
user.mobilePhoneNumber = "+8618200008888"
user.put("gender", "secret")
user.signUpInBackground().subscribe(object : Observer<LCUser?> {
override fun onSubscribe(d: Disposable) {
Log.e(TAG, "onSubscribe: "+ d.toString() )
}
override fun onNext(t: LCUser) {
Log.e(TAG, "注册成功: "+ t.toJSONString() )
}
override fun onError(e: Throwable) {
Log.e(TAG, "注册失败: "+ e.message.toString() )
}
override fun onComplete() {
}
})
}
}