我在更改主屏幕墙纸的 IO 线程上有简单的工作,之后我尝试在 UI 线程上运行一些动画:
AppObservable.bindFragment(this, Observable.just(0))
.observeOn(Schedulers.io())
.subscribe(v -> setWallpaperOnSeparateThread());
private void setWallpaperOnSeparateThread() {
WallpaperHelper.setBitmapAsWallpaper(photoViewAttacher.getVisibleRectangleBitmap(), getBaseActivity());
AppObservable.bindFragment(this, Observable.just(0))
.delay(500, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(integer -> loadFinishAnimationAfterSetWallpaper());
}
但这种方法会导致错误:
java.lang.IllegalStateException: Observers must subscribe from the main UI thread, but was Thread[RxCachedThreadScheduler-1,5,main]
我试图将第二个 Observable 更改为:
AppObservable.bindFragment(this, Observable.just(0))
.delay(2000, TimeUnit.MILLISECONDS)
.observeOn(Schedulers.io())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(integer -> loadFinishAnimationAfterSetWallpaper());
但这没有帮助。