Created
December 13, 2012 22:18
-
-
Save joshdholtz/4280582 to your computer and use it in GitHub Desktop.
Listening and sending broadcasts
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
public class HomeActivity extends Activity { | |
@Override | |
public void onResume() { | |
super.onResume(); | |
registerReceiver(myBroadcastReceiver, new IntentFilter("com.package.name.BROADCAST_NAME_GOES_HERE")); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
unregisterReceiver(myBroadcastReceiver); | |
} | |
private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent data) { | |
// This is what gets called when you broadcasts gets sent out | |
} | |
}; | |
} |
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
// Use this to send the broadcast | |
context.sendBroadcast(new Intent("com.package.name.BROADCAST_NAME_GOES_HERE")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment