android - RxJava 在onNext(User user) 可以把user赋值给外部成员变量mUser吗?
阿神
阿神 2017-04-17 17:51:12
0
3
615

我刚学RxJava, 执行完下面的代码 mUser还是null 原因会不会是异步造成的,纯属猜测,,请路过的大大帮忙看看,非常感谢OvO~

另外,想请教下你们对于从网络取到的user一般怎么处理?/?

阿神
阿神

闭关修行中......

reply all(3)
黄舟

doOnNext will be called before onNext, which is usually some preparation work. I don’t know why you write the same code in onNext and doOnNext..... Also, you should be using retrofit. I don’t know if Retrofit’s Build has it. That’s right, so it’s possible that the User information is not obtained at all. RxJava is a library specifically designed to handle asynchronous streams, so there is no “asynchronous problem” you mentioned

How to handle it depends on your business needs. For example, you will make a request to get the local weather based on the user's region; or filter out certain users who are younger than 18 years old

大家讲道理

In asynchronous programming, after the code is executed, it is equivalent to scheduling a task. The task may not have started yet. The callback will not be executed until the asynchronous task is completed to get the real return value

For example:
It’s time to go to bed. Tell your wife that I want to eat egg pancakes tomorrow morning and call me when she’s ready.
When you finish saying this, where are the egg pancakes? What about egg pancakes?
Obviously it will have to wait until tomorrow morning

洪涛

Remove the doOnNext operator and try again

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template