How To Unsubscribe To An Rxjava Call In A Broadcast Receiver
Solution 1:
As pointed out here, you should not perform long tasks on broadcast receiver. Broadcast Receivers don't have lifecycle, when your onReceive returns it considered done by the system and your entire process might be killable afterwards, it will returns immediately at your case as you performing async processing. (read more here https://developer.android.com/guide/components/broadcasts.html under "Effects on process state").
You should create a dedicated Service for this task and perform the email sending there, with Service you have clear lifecycle, and you should unsubscribe at onDestory()
. also pay attention to limited background processing and internet access starting with Marshmallow and Doze.
In any case you shouldn't dispose at onNext
/onCompleted
, the Observable will trigger dispose logic when it's terminated (onCompleted
/onError
).
Post a Comment for "How To Unsubscribe To An Rxjava Call In A Broadcast Receiver"