I need to return values from contacts which are retrieved from the phone with an observable. The problem, is the returning value.
I have the next method in a bridge:
@JavascriptInterface
public String getFavoriteUsers() {
return getBridgeHelper().getFavoriteUsers();
}
It is calling a method in a helper (which is the class how do the tasks) and inside of this helper:
@SuppressLint("CheckResult")
public String getFavoriteUsers() {
Observable.fromCallable(() -> {
SharedPreferences sp = getContext().getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
String userIdStores = sp.getString(Constants.SP_FAVOURITES, "[]");
return new Gson().toJson(ContactsManager.findContactsById(ContactsData.getInstance().contactsStored, userIdStores));
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
result -> returnObservedContacts(result),
throwable -> LoggerManager.handlesError(TAG, throwable, throwable.getMessage())
);
}
So, I need to return this result to the previous bridge, but I don't have a clear idea how to do that.
Thanks
SOLUTION:
The solution is to removes subscribe from the Observable and add blockingFirst at the end. Then, we can make the observable to return a value.