kaushikgopal / RxJava-Android-Samples

Learning RxJava for Android by example
Apache License 2.0
7.55k stars 1.37k forks source link

force close on sample bg work #65

Closed siavashabdoli closed 8 years ago

siavashabdoli commented 8 years ago

I click on button several times then press back and go to first page. then this error occurs: at com.morihacky.android.rxjava.fragments.ConcurrencyWithSchedulersDemoFragment$2.onCompleted(ConcurrencyWithSchedulersDemoFragment.java:100) if you unsibscribe the listener why this happen? can fix this issue pls :)

marukami commented 8 years ago

The issue is that every time you click a new subscription gets created and any already existing subscription leaks. The old subscription will still get GCed, but It will also still call the Observer, and that's what's happening here. Since the fragment is gone, we get NPE's.

Check out the PR I made for the simplest fix.

kaushikgopal commented 8 years ago

77 should address this. Thanks @siavashabdoli for noticing this issue and @marukami for a beautiful explanation of the root cause 👍