Reputation: 1166
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
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:localbroadcastmanager:28.0.0'
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
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
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
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