Reputation: 1
I am calling a function in service to send data to activity, i am using Local broadcast manager for this, the below is the code in service
private void sendDataToActivity(List<WNotificationModel> notificationList) {
Intent intent=new Intent("listDataUpdate");
intent.putExtra("hello","helloWorld");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
the below is the code for receiving data in activity
public class WNotificationList extends AppCompatActivity {
private BroadcastReceiver mMessageReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String name=intent.getStringExtra("hello");
Log.d("catAndDog", "onReceive: "+name);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_where_am_ilist_notification);
}
@Override
protected void onStart() {
super.onStart();
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mMessageReceiver,new IntentFilter("listDataUpdate"));
}
@Override
protected void onStop() {
super.onStop();
LocalBroadcastManager.getInstance(getApplicationContext()).unregisterReceiver(mMessageReceiver);
}
}
Upvotes: 0
Views: 49
Reputation: 216
There are some updates in broadcast.
Beginning with Android 9 (API level 28), The NETWORK_STATE_CHANGED_ACTION broadcast doesn't receive information about the user's location or personally identifiable data.
In addition, if your app is installed on a device running Android 9 or higher, system broadcasts from Wi-Fi don't contain SSIDs, BSSIDs, connection information, or scan results. To get this information, call getConnectionInfo() instead.
Beginning with Android 8.0 (API level 26), the system imposes additional restrictions on manifest-declared receivers.
If your app targets Android 8.0 or higher, you cannot use the manifest to declare a receiver for most implicit broadcasts (broadcasts that don't target your app specifically). You can still use a context-registered receiver when the user is actively using your app.
Please have a look in Developer.android.com
Let see if this can help you.
Upvotes: 0