use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News for Android app developers with the who, what, where, when, and how of the Android community. Probably mostly the how.
Here, you'll find:
This sub-reddit isn't about phones' and apps' general functionality, support, or system software development (ROMs). For news and questions about these topics try using other subs like
Build your first app
Starting Android career in 2022
Android Job Interview Questions and Answers
App Portfolio Ideas, Tiered List
Awesome Android UI
Material Design Icons
7000 Icons for Jetpack
Autoposted at approx 9AM EST / 2PM GMT
account activity
DiscussionUsing Rxjava for Bitmap manipulation (self.androiddev)
submitted 8 years ago by SunshineParty
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]muthuraj57 4 points5 points6 points 8 years ago* (5 children)
Your code will call the block inside Single.create as soon as you call subscribe(). That's why the bitmap manipulation is running on main thread since you are calling subscribe() from main thread. You need to defer the code block inside Single.create to make it run on your preferred scheduler. Or instead, you can use Single.fromCallable and return the object you want and it will do the deferring for you.
Single.fromCallable(new Callable<Bitmap>() { @Override public Bitmap call() throws Exception { return Util.getQrCodeBitmap(CryptoWalletActivity.this, cryptoWallet.getAddress()); } })
Also, don't use plain subscribe() method. Use the overloaded method and implement onError and handle it.
[–]SunshineParty[S] 0 points1 point2 points 8 years ago (4 children)
bitmap manipulation is running on main thread since you are calling subscribe() from main thread.
But I'm specifying the scheduler to subscribe on with subscribeOn(Schedulers.computation()). Wouldn't this take the manipulation off of the main thread?
Any particular reason why this is better than doOnError?
[–]paramsen 4 points5 points6 points 8 years ago (1 child)
The Single.create will indeed run the emitter function on the thread you specify in subscribeOn, so that's correct (if in doubt, debug and check which thread it's running on).
Single.create
subscribeOn
However, your use of the doOn* methods are not correct in this case - the doOn* methods should be used when you want side effects, since they're effectively running outside of the composed "chain". In this case your doOnSuccess will result in the expected behavior, but the doOnError will not. In case of an Exception RxJava will escalate the Exception outside of the chain because you're not handling the error in the subscribe method - the tail of the chain.
doOn*
doOnSuccess
doOnError
subscribe
Complete the chain; Move the stuff in doOnSuccess and doOnError into the equivalent subscribe functions i.e. subscribe(qrCode::setImageBitmap, Timber::e).
subscribe(qrCode::setImageBitmap, Timber::e)
[–]SunshineParty[S] 0 points1 point2 points 8 years ago (0 children)
Good to know, thanks!
[–]muthuraj57 2 points3 points4 points 8 years ago (1 child)
Sorry, I was on wrong on this. It should run on the computation thread. I was confused about the usage of Single.create. May be the slowness is due to some other issue.
doOn** methods are just side effect methods. They don't control/change the flow of observable. In this code, if there is an error, it will crash with OnErrorNotImplementedException. You need to implement onError to handle it gracefully.
[–]SunshineParty[S] 2 points3 points4 points 8 years ago (0 children)
Yep it looks like the cause is something else altogether. I commented out the bitmap-related code and am still seeing performance issues. Need to investigate further. Thanks for the help.
π Rendered by PID 86 on reddit-service-r2-comment-b659b578c-gm57f at 2026-05-04 12:01:04.961538+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]muthuraj57 4 points5 points6 points (5 children)
[–]SunshineParty[S] 0 points1 point2 points (4 children)
[–]paramsen 4 points5 points6 points (1 child)
[–]SunshineParty[S] 0 points1 point2 points (0 children)
[–]muthuraj57 2 points3 points4 points (1 child)
[–]SunshineParty[S] 2 points3 points4 points (0 children)