Is it really necessary to use AndroidObservable.bindActivity(...) in cases like activity below? Since you still need to unsubscribe manually in onDestroy .
According to this blog , bindActivity is needed like this:
you do not accidentally try to change state after this is true.
which, as I read it, will mean that there may be problems when you perform certain actions with activity after calling finish() , and therefore the cancellation in onDestroy will be too late.
Can someone give me an example of when unsubscribing already in onDestroy would be a problem?
If you look at the source for AndroidObservable.java , the predicate function used for bindActivity:
private static final Func1<Activity, Boolean> ACTIVITY_VALIDATOR = new Func1<Activity, Boolean>() { @Override public Boolean call(Activity activity) { return !activity.isFinishing(); } };
It would not be better to check configuration changes, for example:
private static final Func1<Activity, Boolean> ACTIVITY_VALIDATOR = new Func1<Activity, Boolean>() { @Override public Boolean call(Activity activity) { return !activity.isFinishing() && !activity.isChangingConfigurations(); } };
???
SomeActivity.java
public class SomeActivity extends Activity implements Observer<String> { private Subscription subscription; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); subscription = getObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(this);
source share