Krishnan V S
Krishnan V S

Reputation: 1166

Android Studio 3.5: not able to resolve LocalBroadcastManager

We are trying implement LocalBroadcastManager in our Android app but facing "Cannot resolve" error.

This is the object we need - https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager

Included the library in app build.gradle (as stated in that page)

implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:localbroadcastmanager:28.0.0'

Included Maven in Solution build.gradle

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Gradle version is 5.4.1

Below line throws "Cannot resolve symbol" error

LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);

Please let me know what we might be missing. Appreciate your help.

Upvotes: 1

Views: 1345

Answers (3)

Anice Jahanjoo
Anice Jahanjoo

Reputation: 8166

I checked it in Android Studio 3.5 and I didn't see any problem. but I use androidX and LocalBroadcastManager imported from androidx.localbroadcastmanager.content.LocalBroadcastManager;

Upvotes: 2

Krishnan V S
Krishnan V S

Reputation: 1166

Thanks for the suggestions, migrating to androidx worked. We are getting the broadcast call to Receiver now. Appreciate the prompt help very much.

Upvotes: 1

cycki
cycki

Reputation: 188

I assume you enabled Jetifier therefore you shouldn't use support dependencies:

Replace

implementation 'com.android.support:support-v4:28.0.0' 
implementation 'com.android.support:localbroadcastmanager:28.0.0'

with

implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

Here's documentation for it: https://developer.android.com/reference/kotlin/androidx/localbroadcastmanager/content/LocalBroadcastManager

Upvotes: 1

Related Questions