Solution for localbroadcostmanager is causing a deprication warning

202 Views Asked by At

I have an android Studio app trying to implement MQTT. The example I am modifying uses androidx.localbroadcastmanager.content.LocalBroadcastManager but it is deprecated. I am trying to replace this with something else but I can't find any good examples. Here is the code that I use.

build.gradle //(module)
dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
}

in JavaClass

import androidx.localbroadcastmanager.content.LocalBroadcastManager;


  private void registerReceiver(BroadcastReceiver receiver) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(MqttServiceConstants.CALLBACK_TO_ACTIVITY);
        LocalBroadcastManager.getInstance(myContext).registerReceiver(receiver, filter);
        receiverRegistered = true;
    }

This seems to be the only place it is used.

I'm sorry if what I have here isn't enough but I am new to this and could use a lot of help. Just let me know what more you need.

1

There are 1 best solutions below

0
user1114881 On

I found that if I just remove the

LocalBroadcastManager.getInstance

from the code and use just

myContext.registerReceiver(receiver, filter);

it works just fine.