0

In 'subcribe' of 'BehaviorSubject', receive 'ArrayList' as a parameter to process data. If you try to pass the accepted data into the Intent and finish it, the app is stopped. What's the problem?

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.
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

I would suggest getting Disposable from BehaviorSubject and dispose it in onDestroy of Activity.

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();
}
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96