greenrobot EventBus has been suggested as replacement of (now deprecated) LocalBroadcastManager. I'm current using LocalBroadcastManager to send intents from service to MainActivity like this:
val intent = Intent("service event")
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
intent.putExtra("param", "some value")
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
That clears the stack and MainActivity becomes visible as the only activity in the stack.
How can I achieve the same (Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) effect when posting EventBus event?
After some experiments, I found a "solution":
onCreate()of MainActivityEventBus.getDefault().register(this). That makes it possible for MainActivity to receive posts even when it is not on top of the activity stack. Then, of course, unregister inonDestroy().Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOPflags, for example like this:I'm new to this and better solutions are appreciated.