Office Hours — Today, January 6

Yesterday, January 5

Jan 6
3:50 PM
Mark M.
has entered the room
3:55 PM
Mark M.
turned on guest access
Wyatt B.
has entered the room
Mark M.
hello, Wyatt!
how can I help you today?
4:00 PM
Wyatt B.
I had a question about a post that you commented on about localbraodcastmanager. http://stackoverflow.com/questions/24081676/bro...
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 :-)
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
LocalBroadcastManager is an implementation of an event bus
there are others, such as greenrobot's EventBus and Square's Otto
I'm a fan of the event bus model and heartily endorse their use
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.
4:05 PM
Mark M.
OK
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
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
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.
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
in your case, you already have a process running
hence, you do not need a receiver in the manifest
if other running components care about logout events, use an event bus
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)
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
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.
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
4:55 PM
Mark M.
turned off guest access

Yesterday, January 5

 

Office Hours

People in this transcript

  • Mark Murphy
  • Wyatt Blake