我使用infinity progres bar创建了简单的活动,并且我试图使用Rx
Java运行耗时的方法来阻止UI线程阻塞,但每次阻止UI线程.我认为我的解决方案在发射Observable方面存在问题.谁能帮我?我是RX的先生.
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void doSomething(View view) { doHeavyStuff() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .doOnNext(new Action1() { @Override public void call(Object o) { Toast.makeText(getApplicationContext(),"FINISHED",Toast.LENGTH_SHORT).show(); } }) .subscribe(); } private Observable doHeavyStuff() { for (int i = 0; i < 999999999; i++) { for (int j = 0; j < 2; j++) { } } return Observable.just(1); }