Task: Send a request to the server with the data and accept the response.
API interface:
@FormUrlEncoded @POST("api/reg") fun registration(@Field("name") name: String, @Field("phone") phone: String, @Field("email") email: String, @Field("password") password: String, @Field("referer") referer: String, @Field("promo") promo: String, @Field("code") deviceId: String): Observable<Response<UserWithKeys>> CallBack for this request:
interface AuthorizationCallBack{ fun userWithKeyCallBack(userWithKeys: UserWithKeys) fun errorCallBack(error: String) } Repository request:
fun registration(name: String, phone: String, email: String, password: String, referer: String, promo: String, deviceId: String, autorizationCallBack: AuthorizCallB, failCallBack: FailCallBack){ val s = serverApi.registration(name, phone, email, password, referer, promo, deviceId) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe({if (it.isSuccessful) autorizationCallBack.userWithKeyCallBack(it.body()!!) }, { failCallBack.throwableCallBack(it) }) } Query Log Presenter
fun registrationNewUser(name: String, phone: String, email: String, pass: String, referer: String, promo: String, myDeviceId: String) { val disposable = repositoryApi.registration(name, phone, email, pass, referer, promo, myDeviceId, object : AuthorizCallB { override fun userWithKeyCallBack(userWithKeys: UserWithKeys) { if (userWithKeys.publickey!=""){ responseeRegistrationNewUser(userWithKeys) Log.i("Loog", "RegistrationFragmentProvider reg - ${userWithKeys!!.id}") } else Log.i("Loog", "RegistrationFragmentProvider reg - null") } override fun errorCallBack(error: String) { showErrorMessage(error) } }, object : FailCallBack { override fun throwableCallBack(throwable: Throwable) { showErrorMessage(throwable.message!!) BugReport().sendBugInfo(throwable.message.toString(), "RegistrationFragmentProvider.registrationNewUser.throwableCallBack") } }) } The problem is that when you call the "registrationNewUser (...)" method, you immediately work out "responseeRegistrationNewUser" in the interface body, and then the server receives a response, the "responseeRegistrationNewUser" method does not work, only the log is triggered.
Logs:
I/Loog: registrationNewUser I/Loog: responseRegistrationNewUser I/Loog: RegistrationFragmentProvider reg - 3119 UserWithKeys class:
class UserWithKeys(var id: Int, var name: String, var phone: String, val email: String, val sum: Int, val score: Int, var level: Int, var publickey: String, var privatekey: String, var refererLink: String, var favorites: Array<Int>) I also use Dagger2. What could be the problem?
responseeRegistrationNewUser()method is also shown. While I do not see the problem at all. - Eugene Krivenja