Jan 6 | 3:50 PM |
Mark M. | has entered the room |
Jan 6 | 3:55 PM |
Mark M. | turned on guest access |
Wyatt B. | has entered the room |
Mark M. |
hello, Wyatt!
|
Mark M. |
how can I help you today?
|
Jan 6 | 4:00 PM |
Wyatt B. |
I had a question about a post that you commented on about localbraodcastmanager. http://stackoverflow.com/questions/24081676/bro...
|
Wyatt B. |
Second, registering in the manifest has little to do with it being "cleaner". It is to allow Android to instantiate the receiver on its own, so that you can respond to broadcasts when your process is not running. And, in the specific example that you cite, it is to allow any app on the system to send you a broadcast. Neither of those are relevant for LocalBroadcastManager.
|
Mark M. |
that paragraph sounds familiar :-)
|
Mark M. |
what is your question?
|
Wyatt B. |
So my question is about LocalBroadcastManager. Should we always use it unless we want to allow others apps to call the broadcastreceiver
|
Mark M. |
um
|
Mark M. |
LocalBroadcastManager is an implementation of an event bus
|
Mark M. |
there are others, such as greenrobot's EventBus and Square's Otto
|
Mark M. |
I'm a fan of the event bus model and heartily endorse their use
|
Mark M. |
personally, I use the greenrobot one, for flexibility
|
Wyatt B. |
So I want to know when a user logs out. so I create a BroadcastReceiver with an intent filter of XXX_LOG_OUT.
|
Jan 6 | 4:05 PM |
Mark M. |
OK
|
Mark M. |
are you expecting a third party app to tell you that the user has logged out?
|
Wyatt B. |
if I broadcast an messing using it using LocalFragementManager.Send()
|
Mark M. |
you are certainly welcome to do that, or use another event bus
|
Mark M. |
system-level broadcasts, particularly those with receivers registered in the manifest, are for when you are expecting something *outside* your app to tell you something
|
Mark M. |
system-level broadcasts are a form of IPC (inter-process communication)
|
Wyatt B. |
then if I had registered the broadcastreceiver in the manifest then my broadcastrecevier I will not get the message like you just typed.
|
Jan 6 | 4:10 PM |
Mark M. |
correct, receivers registered via <receiver> elements in the manifest are for system-level broadcasts, not LocalBroadcastManager
|
Wyatt B. |
I would have had to register for the receiver outside the manifest
|
Mark M. |
correct, by calling LocalBroadcastManager.getInstance().registerReceiver()
|
Wyatt B. |
If I use greenrobot's bus could I register broadcast receivers in the manifiest (or xml file) instead of having to do it in an activity?
|
Mark M. |
no
|
Wyatt B. |
I like the idea, maybe it's not the correct way to do it, of having a receiver that will respond if any where in my app when someone broadcasts a XXX_USER_HAS_LOGGED_OUT message
|
Mark M. |
the point behind having a receiver in the manifest is so that you can respond to system-level broadcasts even if you do not have a process running
|
Mark M. |
in your case, you already have a process running
|
Mark M. |
hence, you do not need a receiver in the manifest
|
Mark M. |
if other running components care about logout events, use an event bus
|
Mark M. |
if you just want to do some specific work when the user has logged out, just put that code in your logic that is triggered when the user clicks the "Logout" button (or whatever)
|
Jan 6 | 4:15 PM |
Wyatt B. |
Sounds good. We need to logout the user from a background task if the user has been fired. I'll look at the greenrobot's even bus.
|
Mark M. |
there are two chapters in the book on event buses
|
Mark M. |
and I use greenrobot's EventBus in a few other samples outside of those chapters as well
|
Wyatt B. |
thanks. we are trying to re-create our IOS app in Android. Trying to get the other devs to not think like IOS and do things the android way.
|
Jan 6 | 4:20 PM |
Mark M. |
if you have other questions, go right ahead -- it is a quiet chat room today
|
Wyatt B. |
Thats all I had for today. Need to remove my IntentFilters from my manifest and read the deal with threads chapter. Thanks, have a good day.
|
Wyatt B. | has left the room |
Jan 6 | 4:55 PM |
Mark M. | turned off guest access |