在 BehaviorSubject 的订阅完成 Activity 时,应用程序崩溃

When finish Activity in BehaviorSubject's subscribe, The application is crashed

在'BehaviorSubject'的'subcribe'中,接收'ArrayList'作为参数处理数据。 如果您尝试将接受的数据传递到 Intent 中并完成它,应用程序将停止。 有什么问题?

subject(requestData)
   .map(r->arrayList = r.getArrayList())
   .observeOn(Android.Schedulers.mainThread())
   .subscribe(r->{ finishWithData(r)});

private void finishWithData(r) {
   Intent intent = new Intent();
   intent.putExtra("array", r);
   setResult(Activity.RESULT_OK, intent);
   finish() // Here is Crash Point.
}

我建议从 BehaviorSubject 获取 Disposable 并将其放置在 Activity 的 onDestroy 中。

Disposable disposable;


disposable = subject(requestData)
              .map(r->arrayList = r.getArrayList())
              .observeOn(Android.Schedulers.mainThread())
              .subscribe(r->{ finishWithData(r)});

@Override
protected void onDestroy() {
    disposable.dispose();
    super.onDestroy();
}