Created
July 11, 2012 16:51
-
-
Save yyl/3091660 to your computer and use it in GitHub Desktop.
local broadcast manager usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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(); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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