RxJava Unable to create a handler inside a thread that did not call Looper.prepare ()

Ok, so I have problems with the RxJava Observable, which I use in my Android application. This is very unpleasant, because it has been working for a long time and is now throwing the error above. I know this means that I am performing a user interface operation from another thread, but I cannot see where this is happening. So here is the observable:

ConnectionsList.getInstance(this).getConnectionsFromParse(mCurrentUser) .delay(3, TimeUnit.SECONDS) .flatMap(s -> mainData.getDataFromNetwork(this, mCurrentUser, mSimpleFacebook)) .flatMap(s -> mainData.getPictureFromUrl(s)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Bitmap>() { @Override public void onCompleted() { if (mCurrentUser.get(Constants.NAME) != null) { mNavNameField.setText((String) mCurrentUser.get(Constants.NAME)); } mSearchFragment.setupActivity(); } @Override public void onError(Throwable e) { e.printStackTrace(); mSearchFragment.setEmptyView(); } @Override public void onNext(Bitmap bitmap) { mNavProfImageField.setImageBitmap(bitmap); mainData.saveImageToParse(bitmap); //save the image to Parse backend } }); 

After some debugging, I found that this flat card is causing the error:

 .flatMap(s -> mainData.getDataFromNetwork(this, mCurrentUser, mSimpleFacebook)) 

Inside this there is the following: I added a comment where an error occurs:

  return Observable.create(subscriber -> { //set the username field if ParseUser is not null if(currentUser != null) { username = (String) currentUser.get(Constants.NAME); } //if prof pic is null then request from facebook. Should only be on the first login if (currentUser != null && currentUser.getParseFile(Constants.PROFILE_IMAGE) == null) { if (AccessToken.getCurrentAccessToken() != null) { //check if session opened properly //get simple facebook and add the user properties we are looking to retrieve Profile.Properties properties = new Profile.Properties.Builder() .add(Profile.Properties.FIRST_NAME) .add(Profile.Properties.GENDER) .add(Profile.Properties.BIRTHDAY) .add(Profile.Properties.ID) .add(Profile.Properties.EMAIL) .build(); //The following line is where the debugger stops //and the error gets thrown simpleFacebook.getProfile(properties, new OnProfileListener() { @Override public void onComplete(Profile response) { String id = response.getId(); String name = response.getFirstName(); String gender = response.getGender(); String birthday = response.getBirthday(); String email = response.getEmail(); String age = getAge(birthday); currentUser.put(Constants.NAME, name); currentUser.put(Constants.AGE, age); currentUser.put(Constants.GENDER, gender); currentUser.put(Constants.EMAIL, email); currentUser.saveInBackground(); if (id != null) { //display the profile image from facebook subscriber.onNext("https://graph.facebook.com/" + id + "/picture?type=large"); } } 

What's going on here? It works fine as it is, and now it says I'm in some sort of supporting topic. As far as I know, so far I have been on the topic of user interface. If someone can help me, that would be great, otherwise I might have to give up RxJava, as that does not work for me. Thanks in advance!

+5
source share
1 answer

It seems that calling simpleFacebook.getProfile(properties, listener) has an internal thread. Usually you do not want this with rxjava. You want rxjava to take care of streaming, and all the code you write should be synchronous.

I am not familiar with the Facebook SDK, but I would be looking for a call that executes the request synchronously. Thus, a method that looks like public Profile getProfile(Properties properties) { instead of one returning void and requiring a listener.

Hope this helps.

0
source

All Articles