Created
October 2, 2017 21:42
-
-
Save PierceZ/493665f49707c7234b4c6befe066de0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseViewModel extends ViewModel { | |
private final List<DataSubscription> mSubscriptions; | |
@Override | |
protected void onCleared() { | |
super.onCleared(); | |
for (DataSubscription subscription : mSubscriptions) { | |
if (!subscription.isCanceled()) { | |
subscription.cancel(); | |
} | |
} | |
} | |
protected final void addSubscription(@NonNull DataSubscription subscription) { | |
mSubscriptions.add(subscription); | |
} | |
public BaseViewModel() { | |
mSubscriptions = new ArrayList<>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment