Situation 1 Take a look at the Composable below, what will happen if the button is clicked?
@Composable fun Situation1() { val names by remember { mutableStateOf(mutableListOf("Bob", "Tom")) } Column { names.forEach { Text(it) } Button(onClick = { names.add("Jane") }) { Text("Add Jane!") } } } Answer The list will still consist of Bob and Tom. Jane will not be added. The reason is that for mutable states, only the assignment operation is “observed”.
I’m planning to write a series of short articles about Android’s Jetpack Compose UI framework. You can use it to test your understanding or maybe learn a few things along the way.
Situation 1 Take a look at the Composable below, what will happen if the button is clicked?
@Composable fun Situation1() { var name = "Guowei" Column { Text(name) Button(onClick = { name = "Hello" }) { Text("Change name!") } } } Answer Nothing.
In this article, we focus on how the dispose system works in RxJava.
First, let’s take a look at the Disposable interface.
public interface Disposable { void dispose(); boolean isDisposed(); } Not much going on here, basically it says a Disposable can be disposed.
First example we are going to examine is:
Observable.interval(1, TimeUnit.SECONDS) If you click through the code, the implementation is actually this class ObservableInterval.
First let’s look at the constructor of this class:
Let’s see what makes RxJava tick.
RxJava is complex, so I will have to (overly) simplify things at places. All of this is just trying to help you to get a better picture of how RxJava is implemented.
Let’s go.
Let’s start with the Single, it’s just an interface with one method:
public interface Single<T> { void subscribe(SingleObserver<T> observer); } So a Single is just a thing that can be subscribed.
It all started from a message sent by my cousin in our family group chat one day.
He posted some of those harder 24 problems, and I couldn’t solve any of them.
(If you don’t know what is this 24 game is all about, here you can read it https://en.wikipedia.org/wiki/24_game)
So, I decided to write a program to help me. And that program turned into a mobile game eventually.