How to use/locate LocalBroadcastManager
as described in google docs and Service broadcast doc?
I tried to google it, but there is no code available to s
On Receiving end:
Then handle incoming intent data in onReceive.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(receiver, new IntentFilter("filter_string"));
}
public BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
String str = intent.getStringExtra("key");
// get all your data from intent and do what you want
}
}
};
On Sending End:
Intent intent = new Intent("filter_string");
intent.putExtra("key", "My Data");
// put your all data using put extra
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);