Skip to content

Instantly share code, notes, and snippets.

@yyl
Created July 11, 2012 16:51
Show Gist options
  • Select an option

  • Save yyl/3091660 to your computer and use it in GitHub Desktop.

Select an option

Save yyl/3091660 to your computer and use it in GitHub Desktop.
local broadcast manager usage
// register the receiver you created and
// add a filter to only receive the intent you need
LocalBroadcastManager.getInstance(this).registerReceiver(
myReceiver, new IntentFilter("location"));
// create your own receiver from BroadcastReceiver class
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// get the info from the intent we received
Double test = intent.getDoubleExtra("test", 20);
Toast.makeText(getBaseContext(), test, Toast.LENGTH_SHORT).show();
}
};
// create an intent to hold your info
Intent intent = new Intent("location");
// put your info into the intent
intent.putExtra("test", 99);
// use LBM to send the intent
LocalBroadcastManager.getInstance(getBaseContext()).sendBroadcast(intent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment