My launch Activity is A.
In A, I have a BroacastReceiver that I want to unregister only if the application (and not only the activity) is not visible anymore.
So, if I launch activity B, A still gets updates from the recevier.
I'm using Cornstalks's answer here and I'm able to unregister the receiver only if the app is not visible anymore:
in A:
@Override
protected void onStop() {
super.onStop();
if (!LifecycleHandler.isApplicationVisible() && dataUpdateReceiver != null)
unregisterReceiver(
}
BUT this works only if the last activity is A. If the user leaves the application from B, the receiver is still registered.
So how can I achieve this?