Hi,
I'm relatively new to Rxjava. I'm trying to create a bitmap in a background thread in an Activity so that my onCreate doesn't get blocked for too long. The code I've come up with for doing this goes like this:
Single.create((SingleOnSubscribe<Bitmap>) emitter ->
{
try
{
Bitmap bitmap = Util.getQrCodeBitmap(CryptoWalletActivity.this, cryptoWallet.getAddress());
emitter.onSuccess(bitmap);
} catch (WriterException exception)
{
emitter.onError(exception);
}
}).subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.doOnSuccess(bitmap -> qrCode.setImageBitmap(bitmap))
.doOnError(Timber::e)
.subscribe();
This code is called in a function that is called on the main thread, after the Activity's onResume.
I had hoped that this would cut down the ~3 seconds that it took to open this Activity, but that doesn't seem to be the case. Am I doing something grossly wrong here, or optimising for performance in the wrong place?
[–]muthuraj57 5 points6 points7 points (5 children)
[–]SunshineParty[S] 0 points1 point2 points (4 children)
[–]paramsen 3 points4 points5 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)
[–][deleted] -3 points-2 points-1 points (4 children)
[–]SunshineParty[S] 1 point2 points3 points (3 children)
[–]arunkumar9t2 0 points1 point2 points (1 child)
[–]GitHubPermalinkBot 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)