Skip to content Skip to sidebar Skip to footer

Passing Parameter To Observable.create

I am using RXJava on Android for asynchronously access the database. I want to save an object in my database. In this way, I created a method which take a final parameter (the obje

Solution 1:

We usually suggest avoiding the use of create because it may seem simple to use it but they usually violate the advanced requirements of RxJava. Instead, you should use one of the factory methods of Observable. In your case, the just factory method will get what you wanted: no final parameter:

public Observable<?> saveEventLog(@NonNull EventLog eventLog) {
    return Observable
    .just(eventLog)
    .doOnNext(e -> {
         DBEventLog log = new DBEventLog(e);
         log.save();
    })
    .ignoreElements();
}

Post a Comment for "Passing Parameter To Observable.create"